Click here to Skip to main content
15,909,953 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalremove deleted records Pin
jafrazee4-Feb-02 5:27
jafrazee4-Feb-02 5:27 
GeneralRe: remove deleted records Pin
Mazdak4-Feb-02 6:12
Mazdak4-Feb-02 6:12 
GeneralRe: remove deleted records Pin
jafrazee4-Feb-02 6:19
jafrazee4-Feb-02 6:19 
GeneralRe: remove deleted records Pin
Mazdak4-Feb-02 6:49
Mazdak4-Feb-02 6:49 
GeneralRe: remove deleted records Pin
jafrazee4-Feb-02 7:58
jafrazee4-Feb-02 7:58 
GeneralRe: remove deleted records Pin
Mazdak4-Feb-02 9:10
Mazdak4-Feb-02 9:10 
GeneralSTL containers Pin
User 98854-Feb-02 5:02
User 98854-Feb-02 5:02 
QuestionImplicit Copy constructor generation bug? Pin
Chen Venkataraman4-Feb-02 4:35
Chen Venkataraman4-Feb-02 4:35 
I ran into this issue while working on a project :- it appears that VC6.0 compiler does not know how to generate the implicit copy constructor when a class has a data member that has more than 1 copy constructor declared. Not sure if this is a known VC6.0 (with SP3) bug.

Here’s example that demonstrates the problem :-

#include <iostream>

class A
{
public:
    	A()             	{ std::cout << "A constructor..." << std::endl; }
    	virtual ~A()    	{ std::cout << "~A destructor..." << std::endl; }

	A(const volatile A& a)	{ std::cout << "A const volatile& copy constructor..." << std::endl; }
	A(const A& a)		{ std::cout << "A const& copy constructor..." << std::endl; }
	//A(A&)			{ std::cout << "A & copy constructor..." << std::endl; }
	//A(volatile A& a)	{ std::cout << "A volatile& copy constructor..." << std::endl; }
};

class B
{
public:
    	B()             { std::cout << "B constructor..." << std::endl; }
    	virtual ~B()	{ std::cout << "~B destructor..." << std::endl; }

private:
	A a_;
};

class C
{
public:
    	C()             { std::cout << "C constructor..." << std::endl; }
    	virtual ~C()	{ std::cout << "~C destructor..." << std::endl; }

const volatile A&	getA()		{ return a_; }
private:
	A a_;
};

int main(int argc, char* argv[], char* envp[])
{
	//A	a1;
	//A	a2(a1);
	//const	A	a3;
	//A	a4(a3);
	//const volatile A a5;
	//A	a6(a5);
        //volatile A a7;
	//A	a8(a7);

	B	b1;
	B	b2(b1);

	C	c1;
	A	a = c1.getA();

	return 0;
}


Compiling this results in “C:\Projects\CopyBug\CopyBug.cpp(46) : error C2558: class 'B' : no copy constructor available”. This issue came about while working on class C which returns a const volatile reference to A & this necessitated adding a new copy constructor to A. Unfortunately, this broke B. Originally, I thought the VC6 compiler did not distinguish between const & volatile modifiers & perhaps this led to the problem. However, it turns out that the compiler is able to invoke the correct copy constructor as illustrated by a2, a4, a6 & a8 objects.

I then removed class C & its related code completely & tried to compile - still the same error. It appears that as soon as the second copy constructor is added to A’s declaration, the compiler fails to generate an implicit copy constructor for B. As long as there is only one copy constructor declared in A (doesn’t matter which one!), B’s implicit copy constructor gets generated properly.

Is this a known bug with VC6(SP3)? Any insights would be appreciated. Thanks.


Chen Venkataraman
AnswerRe: Implicit Copy constructor generation bug? Pin
Joaquín M López Muñoz4-Feb-02 6:00
Joaquín M López Muñoz4-Feb-02 6:00 
General.ini path Pin
XAlien4-Feb-02 3:55
XAlien4-Feb-02 3:55 
GeneralRe: .ini path Pin
Fredrik Skog4-Feb-02 4:42
Fredrik Skog4-Feb-02 4:42 
GeneralRe: .ini path Pin
Carlos Antollini4-Feb-02 5:03
Carlos Antollini4-Feb-02 5:03 
GeneralOwner draw controls Pin
Juvenal4-Feb-02 2:51
Juvenal4-Feb-02 2:51 
GeneralRe: Owner draw controls Pin
Mazdak4-Feb-02 3:39
Mazdak4-Feb-02 3:39 
GeneralRe: Owner draw controls Pin
User 66584-Feb-02 3:47
User 66584-Feb-02 3:47 
GeneralThank You ever so much! Pin
Juvenal4-Feb-02 4:55
Juvenal4-Feb-02 4:55 
Generalactivex controls Pin
4-Feb-02 1:54
suss4-Feb-02 1:54 
GeneralRe: activex controls Pin
Joaquín M López Muñoz4-Feb-02 2:27
Joaquín M López Muñoz4-Feb-02 2:27 
GeneralRe: activex controls Pin
Jon Hulatt4-Feb-02 4:35
Jon Hulatt4-Feb-02 4:35 
GeneralProcess Memory Pin
StuartHall4-Feb-02 0:42
StuartHall4-Feb-02 0:42 
GeneralSelecting A Directory - Common Dialogs Pin
AJ1234-Feb-02 0:04
AJ1234-Feb-02 0:04 
GeneralRe: Selecting A Directory - Common Dialogs Pin
Christian Graus4-Feb-02 0:04
protectorChristian Graus4-Feb-02 0:04 
QuestionExpoert advice on MFC TCP/IP sockets, please? Pin
Peter Sjöström3-Feb-02 23:31
Peter Sjöström3-Feb-02 23:31 
AnswerRe: Expoert advice on MFC TCP/IP sockets, please? Pin
Joaquín M López Muñoz3-Feb-02 23:51
Joaquín M López Muñoz3-Feb-02 23:51 
GeneralRe: Expoert advice on MFC TCP/IP sockets, please? Pin
Peter Sjöström3-Feb-02 23:59
Peter Sjöström3-Feb-02 23:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.