473,287 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

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 1499
* 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
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)); ...
106
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...
28
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()',...
4
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...
7
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...
6
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...
0
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...
1
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"...
6
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"...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.