473,516 Members | 2,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

object construction recognized as function declaration

Hi @all,

there are always details, why it isn't possible to create a consistent
framework :(
However, here some code:

//--------------

class foo
{
public:
foo(){}
};

class fooConst
{
public:
explicit fooConst(const foo &p_Foo){}
void doSomething() {}
};

void test()
{
fooConst myObject(foo());
myObject.doSomething(); // <--- Error
}

//--------------

This doen't work on all compilers I have tested, because "fooConst
myObject(foo());" is assumed to be a funtion declaration!

I know that I could write:

foo aFoo;
fooConst myObject(aFoo);

But I don't want to!

Is there another keyword, possibility,........ you can think of ???

Greetings,
Kirsten

Jun 2 '06 #1
8 1503
* tt******@gmx.de:
Hi @all,

there are always details, why it isn't possible to create a consistent
framework :(
However, here some code:

//--------------

class foo
{
public:
foo(){}
};

class fooConst
{
public:
explicit fooConst(const foo &p_Foo){}
void doSomething() {}
};

void test()
{
fooConst myObject(foo());
myObject.doSomething(); // <--- Error
}

//--------------

This doen't work on all compilers I have tested, because "fooConst
myObject(foo());" is assumed to be a funtion declaration!

I know that I could write:

foo aFoo;
fooConst myObject(aFoo);

But I don't want to!

Is there another keyword, possibility,........ you can think of ???


You can

* Declare the argument object as a local variable, or

* use extra parentheses, or

* use the old "=" initialization syntax.

You should

* Try to include fewer misdirections in your examples.

Hth.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jun 2 '06 #2
> You can

* Declare the argument object as a local variable, or

As I already mentioned, this would be a nasty break in constistence. I
don't really want to.
* use extra parentheses, or

Where exactly?
* use the old "=" initialization syntax.


Not possible, because explicit
THX,
Kirsten

Jun 2 '06 #3
* tt******@gmx.de:
You can

* Declare the argument object as a local variable, or


As I already mentioned, this would be a nasty break in constistence. I
don't really want to.


It may be for the best, for it wouldn't suprise me if otherwise you'll
end up with a dangling reference or pointer.

* use extra parentheses, or


Where exactly?


You can always parenthesize an expression, such as an actual argument,
and if you look this up in the standard you'll find just that as an
example on how to do this.

* use the old "=" initialization syntax.


Not possible, because explicit


I'm sorry, but that's incorrect. In some news-groups a good way to get
a concrete example is to say "that's impossible". In this group, you're
more likely to elicit responses such as "what's your textbook?" (this
one is common because there really are a lot of bad C++ textbooks).

Anyway, I'll let you figure out why your statement is incorrect.

Just ask again if that's, uh, "impossible"... ;-)

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jun 2 '06 #4
tt******@gmx.de wrote:
You can

* Declare the argument object as a local variable, or


As I already mentioned, this would be a nasty break in constistence. I
don't really want to.
* use extra parentheses, or


Where exactly?

fooConst myObject( ( foo() ) );
^ ^
* use the old "=" initialization syntax.


Not possible, because explicit


fooConst myObject = myObject(foo());
--
Alan Johnson
Jun 2 '06 #5
Alan Johnson wrote:
* use the old "=" initialization syntax.


Not possible, because explicit


fooConst myObject = myObject(foo());


Sorry,

fooConst myObject = fooConst(foo());

--
Alan Johnson
Jun 2 '06 #6
> >
Where exactly?

fooConst myObject( ( foo() ) );
^ ^


Sorry, this does not work on my compiler Borland C++ Builder 6.0...
I've already tried that.

* use the old "=" initialization syntax.


Not possible, because explicit


fooConst myObject = myObject(foo());


After I have posted my last reply I thought about this, right... but
I'm sorry, because I have forgotten an important fact in my example:
the assignment operator and copy constructor are hidden!

Jun 2 '06 #7
tt******@gmx.de wrote:
Hi @all,

there are always details, why it isn't possible to create a consistent
framework :(
However, here some code:

//--------------

class foo
{
public:
foo(){}
};

class fooConst
{
public:
explicit fooConst(const foo &p_Foo){}
void doSomething() {}
};

void test()
{
fooConst myObject(foo());
myObject.doSomething(); // <--- Error
}

//--------------

This doen't work on all compilers I have tested, because "fooConst
myObject(foo());" is assumed to be a funtion declaration!

I know that I could write:

foo aFoo;
fooConst myObject(aFoo);


google for "most vexing parse"

Jun 2 '06 #8

red floyd schrieb:
google for "most vexing parse"


Thank you for this nice headword!

Jun 2 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2981
by: Alexander Stippler | last post by:
Can someone explain the following construct to me: What is not clear to me is what the argument to foo is. A pointer to a member? template <class U> static char foo(void (U::*)(void)); regards, alex
106
5476
by: A | last post by:
Hi, I have always been taught to use an inialization list for initialising data members of a class. I realize that initialsizing primitives and pointers use an inialization list is exactly the same as an assignment, but for class types it has a different effect - it calls the copy constructor. My question is when to not use an...
28
20276
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()', this.pinginterval); - but is there no way to do this without using the literal ObjectName? If I write 'this.methodName()' I get "Line 1 Char 1: Object...
4
1665
by: Jerivix Entadi | last post by:
I'm attempting to create an application to work with a fluid database of people. I'm doing this in a command line, text-based manner. I need to know two things: 1) How do I save data, perhaps a group of objects and their memebers or a few lines of text? and 2) Is there any way to automate object construction? I'm thinking that I can create a...
7
1463
by: Dave | last post by:
Hello all, In the code below, I use a pointer to an object under construction. Is the usage below legal? I have come across similar code at work. It compiles, but I'm not sure it's really legal... Thanks, Dave struct D;
6
2315
by: Luke | last post by:
Here is my emails to Danny Goodman (but probably he is very busy so he didn't answered it). First email(simple): Subject: JavaScript Arrays " We all know the array can act like HashMap, but is there a shortcut for creating such array ? eg //simple array indexed via numbers var a = new Array("a", "fdsf", "sada"); or,
0
938
by: Sam Samnah | last post by:
Hi everyone. I don't know why but on the outputed page the dialog helper id is not recognized or is "undefined" Can someone tell suggest what I am doing wrong? I've been going over this goodness knows how many times and I can't figure it out. The Object is set on the page properly but is not recognized in the javascript. Some one please...
1
6446
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located...
6
1855
by: burningodzilla | last post by:
Hi all - I'm preparing to dive in to more complex application development using javascript, and among other things, I'm having a hard time wrapping my head around an issues regarding "inheritance" using the prototype property. I realize there are no classes in JS, that code therefore lives in objects instead of class definitions, and that...
0
7276
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7581
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7548
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5714
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4773
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3267
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1624
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.