Declaration error



 DEVELOP > c-Plus-Plus > Declaration error

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Pierre Couderc"
Date: 04 Jan 2007 07:44:27 AM
Object: Declaration error
What do I do wrong?
class CTest
{
public:
CTest(int uu);
};
void ttt()
{
int uu=88;
CTest(uu);
CTest(88);
}
I get 2 errors that I do not understand on CTest(uu) with MSVC6 :
error C2371: 'uu' : redefinition; different basic types
error C2512: 'CTest' : no appropriate default constructor available
I have a way CTest((int) uu); to get it working, but I would like to
understand where is the problem...
Thank you in advance
Pierre Couderc
.

User: "Bernhard Berger"

Title: Re: Declaration error 04 Jan 2007 08:16:47 AM
Hi,

What do I do wrong?

You forgot the names of the variables.

class CTest
{
public:
CTest(int uu);
};

void ttt()
{
int uu=88;
CTest foo(uu);
CTest bar(88);
}

This one should work.
Bernhard 'berber' Berger
.
User: "Victor Bazarov"

Title: Re: Declaration error 04 Jan 2007 08:22:20 AM
Bernhard Berger wrote:

Hi,

What do I do wrong?

You forgot the names of the variables.

class CTest
{
public:
CTest(int uu);
};

void ttt()
{
int uu=88;
CTest foo(uu);
CTest bar(88);
}

This one should work.

Bernhard 'berber' Berger

Just to suggest something on posting practices: NEVER correct
the posting to which you respond by changing the text which you
quote. ALWAYS place your corrections after the text which you
are correcting. Do it like this:
[original text, which you quote:]

int uu=88;
CTest(uu);
CTest(88);

[your correction:]
CTest foo(uu);
CTest bar(88);
Otherwise it seems that the original poster (whose message you
quoted) did everything right in the first place.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
.


User: "Pierre Couderc"

Title: Re: Declaration error 04 Jan 2007 08:57:07 AM
Pierre Couderc a écrit :

What do I do wrong?

class CTest
{
public:
CTest(int uu);
};

void ttt()
{
int uu=88;
CTest(uu);
CTest(88);
}


I get 2 errors that I do not understand on CTest(uu) with MSVC6 :
error C2371: 'uu' : redefinition; different basic types
error C2512: 'CTest' : no appropriate default constructor available

I have a way CTest((int) uu); to get it working, but I would like to
understand where is the problem...

Thank you in advance

Pierre Couderc

My (bad)idea was that it was not necessary to declare an explicit name
as the constructor of CTest makes all the work....
Thank you all.
Pierre Couderc
.
User: "Victor Bazarov"

Title: Re: Declaration error 04 Jan 2007 09:03:42 AM
Pierre Couderc wrote:

Pierre Couderc a écrit :

What do I do wrong?

class CTest
{
public:
CTest(int uu);
};

void ttt()
{
int uu=88;
CTest(uu);
CTest(88);
}


I get 2 errors that I do not understand on CTest(uu) with MSVC6 :
error C2371: 'uu' : redefinition; different basic types
error C2512: 'CTest' : no appropriate default constructor available

I have a way CTest((int) uu); to get it working, but I would like to
understand where is the problem...

Thank you in advance

Pierre Couderc


My (bad)idea was that it was not necessary to declare an explicit name
as the constructor of CTest makes all the work....

To overcome the "what looks like a declaration is a declaration" issue
in your code, surround the type with parens, not the value:
(CTest)uu;
It stops being a declaration and achieves the same point: constructing
a temporary of type CTest from 'uu'. The compiler can still optimize it
away, though. You should consider a simple stand-alone function.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
.


User: "mlimber"

Title: Re: Declaration error 04 Jan 2007 08:19:27 AM
Pierre Couderc wrote:

What do I do wrong?

class CTest
{
public:
CTest(int uu);
};

void ttt()
{
int uu=88;
CTest(uu);
CTest(88);
}


I get 2 errors that I do not understand on CTest(uu) with MSVC6 :
error C2371: 'uu' : redefinition; different basic types
error C2512: 'CTest' : no appropriate default constructor available

I have a way CTest((int) uu); to get it working, but I would like to
understand where is the problem...

You forgot the object name, and the compiler thinks you're declaring a
CTest object by the name of uu, but there is already an int by that
name in the current scope. Try:
CTest c( uu ); // Works fine
This problem is similar to the one described in this FAQ:
http://parashift.com/c++-faq-lite/ctors.html#faq-10.19
Cheers! --M
.

User: "Rolf Magnus"

Title: Re: Declaration error 04 Jan 2007 08:16:58 AM
Pierre Couderc wrote:

What do I do wrong?

class CTest
{
public:
CTest(int uu);
};

void ttt()
{
int uu=88;
CTest(uu);
CTest(88);
}


I get 2 errors that I do not understand on CTest(uu) with MSVC6 :
error C2371: 'uu' : redefinition; different basic types
error C2512: 'CTest' : no appropriate default constructor available

In
CText(uu);
the parens are superfluous. It means the same as
CText uu;
so in your first line in main, you define an int named uu, and in the next
line, a definition of a default-contructed CText with the same name
follows.
.


  Page 1 of 1

1

 


Related Articles
codecvt.cc:39: error: ISO C++ forbids declaration of`_RWSTD_NAMESPACE_BEGIN' with no type
/usr/include/bits/waitstatus.h:78: error: declaration of `unsigned int
Compile error : Type name expected in typedef declaration on aCC HPUX11.0
error: declaration of `operator==' as non-function
error: template-id does not match any template declaration
Linker error - VS2005 thinks it's a function declaration?
About error MIDL2337 : unsatisfied forward declaration
compilation error with forward declaration
error: conflicts with new declaration with =?UTF-8?B?4oCYQ+KAmSBs?==?UTF-8?B?aW5rYWdl?=
implicit declaration of function 'int func(...)' error
defining class-object declaration in header gives error
Forward Declaration produces an error (no cyclic dependencies tho)
Another Curious C++ Error - Illegal Left Operand
Logical error/ whole program contained within.
compilation error
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER