473,394 Members | 1,722 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,394 software developers and data experts.

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
Jan 4 '07 #1
6 3458
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
Jan 4 '07 #2
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.

Jan 4 '07 #3
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

Jan 4 '07 #4
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
Jan 4 '07 #5
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
Jan 4 '07 #6
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
Jan 4 '07 #7

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

Similar topics

83
by: Alexander Zatvornitskiy | last post by:
Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Pascal, or special syntax in...
3
by: Michael Sgier | last post by:
Hello with the original code below I get the error: "forward declaration of `struct CPlayer'" class CPlayer; // what does this do? Instantiate the class CPlayer? // what's a forward...
2
by: Legendary Pansy | last post by:
Hello, I'm trying to accomplish the impossible by trying to do something equivalent of this example found here http://www.c-sharpcorner.com/Code/2003/Dec/DialogTutorial.as Starting with "Listing...
3
by: Wild Wind | last post by:
Hello, I made a post relating to this issue a while back, but I haven't received any answer, so here I am again. I am writing a mixed C++ dll which uses the following declaration: typedef...
1
by: HappyHippy | last post by:
Hi, I have a question about forward declaration of classes. First of all, a simple working example, which compiles and works with no problems. ///file class_a.h:/ #ifndef __CLASS_A_H__...
6
by: Hunk | last post by:
Hi I have a question on usage of forward declarations of templates. While searching through this group , people suggested using forward declarations and typedefs for templates as // in...
14
by: subramanian100in | last post by:
Consider the following program: #include <iostream> using namespace std; int main() { int i;
4
by: subramanian100in | last post by:
Consider the following: Class Test { public: Test(Test_int arg) : val(arg) { } typedef int Test_int; private:
6
by: WaterWalk | last post by:
I find friend declaration just very tricky. I tried the following examples on both MingW(gcc 3.4.2) and VC++ 2005. The results are surprising. Example1: namespace ns1 { class Test { friend...
6
by: samsneelam | last post by:
Hi.. This is samuel, while doing a program, i encountered this problem.. Let me give you clarity regarding my prob.. I am having two files .. one is mpcplib.h it contains the follwing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.