Click here to Skip to main content
15,886,799 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Database layer generator Pin
Zdeslav Vojkovic2-Jan-06 23:57
Zdeslav Vojkovic2-Jan-06 23:57 
GeneralRe: Database layer generator Pin
Francisco José Sen del Prado3-Jan-06 8:15
Francisco José Sen del Prado3-Jan-06 8:15 
QuestionIcon of cursor Pin
kendao1-Jan-06 22:41
kendao1-Jan-06 22:41 
AnswerRe: Icon of cursor Pin
Owner drawn1-Jan-06 22:48
Owner drawn1-Jan-06 22:48 
AnswerRe: Icon of cursor Pin
ThatsAlok1-Jan-06 23:06
ThatsAlok1-Jan-06 23:06 
Questioncould anybody please explain to me how come this happen? Pin
ewighell1-Jan-06 22:21
ewighell1-Jan-06 22:21 
AnswerRe: could anybody please explain to me how come this happen? Pin
sunit51-Jan-06 22:52
sunit51-Jan-06 22:52 
AnswerRe: could anybody please explain to me how come this happen? Pin
rabih_kai1-Jan-06 22:58
rabih_kai1-Jan-06 22:58 
I've got you these from MSDN i think you will understand why? let me know in case not

SYMPTOMS
When a user-defined class contains a CArray and the same user-defined class is nested in another class, you may get the following errors if no copy constructor and assignment operator are provided for the class:
main.cpp(52): error C2664: 'Add' : cannot convert parameter 1 from 'class B' to 'class B' No copy constructor available for class 'B'
After adding a copy constructor, you get the following error message:
afxtempl.h(443): error C2582:'B' : 'operator =' function is unavailable afxtempl.h(1566):while compiling class-template member function 'void __thiscall CArray<class b,class="" b="">::SetAtGrow(int,class B)'
CAUSE
If the class that contains a CArray is nested in another class, then its objects must be copied.

The compiler does not construct an implicit copy constructor and copy assignment operator because the class in question has CArray as a member, which does not have a copy constructor and copy assignment operator, and CArray inherits from CObject, which has a protected copy construtor and a copy assignment operator. The compiler tries to generate the implicit ones, but that generates a call to CObject's version of them. Because they are protected, the above errors are generated.
RESOLUTION
You need to provide a copy constructor and an assignment operator for the class.
STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

This problem was corrected in Microsoft Visual C++ .NET.

MORE INFORMATION
The following example shows the correct use of the CArray class:
// No compiler option needed.
#include <afxtempl.h>

struct A
{
int i;
int j;
};

class B
{

public:
B();
~B();

// Need to define copy ctor and assignment operator.

B(const B& b){
// Your copy ctor body goes here.
}

/* const B& */ void operator= (const B& b) {
// Your assignment operator body goes here.
}

protected:
CArray<a, a=""> arrayA;
};

B::B(){}
B::~B(){}

class C
{

public:
C();
~C();
void addElement();

protected:
CArray<b, b=""> arrayB;
};

C::C(){}
C::~C(){}
void C::addElement()
{
B temp;
arrayB.Add(temp);
}

void main()
{
}



I've been programming since year 1999, graduated from Univeristy Paris 2 France, fluent in C,C++,VC++,Web programming (XML,HTML,php etc..),.NET frameworks,C# and ASP.NET,SQL server, Mastering VC++ .NET and SQL server,data structure and database design
GeneralRe: could anybody please explain to me how come this happen? Pin
ewighell1-Jan-06 23:17
ewighell1-Jan-06 23:17 
GeneralRe: could anybody please explain to me how come this happen? Pin
rabih_kai2-Jan-06 2:08
rabih_kai2-Jan-06 2:08 
GeneralRe: could anybody please explain to me how come this happen? Pin
ewighell2-Jan-06 15:06
ewighell2-Jan-06 15:06 
AnswerRe: could anybody please explain to me how come this happen? Pin
Owner drawn1-Jan-06 23:06
Owner drawn1-Jan-06 23:06 
GeneralRe: could anybody please explain to me how come this happen? Pin
ewighell2-Jan-06 1:55
ewighell2-Jan-06 1:55 
QuestionSimple DLL Question... Pin
Axonn Echysttas1-Jan-06 22:14
Axonn Echysttas1-Jan-06 22:14 
AnswerRe: Simple DLL Question... Pin
sunit51-Jan-06 22:29
sunit51-Jan-06 22:29 
GeneralRe: Simple DLL Question... Pin
sunit51-Jan-06 22:31
sunit51-Jan-06 22:31 
GeneralRe: Simple DLL Question... Pin
Axonn Echysttas1-Jan-06 23:34
Axonn Echysttas1-Jan-06 23:34 
QuestionAssignProcessToJobObject from a different process Pin
Chintoo7231-Jan-06 21:50
Chintoo7231-Jan-06 21:50 
Questionhow to get my IP Pin
islheg1-Jan-06 21:21
islheg1-Jan-06 21:21 
AnswerRe: how to get my IP Pin
mehrdadov1-Jan-06 22:11
mehrdadov1-Jan-06 22:11 
AnswerRe: how to get my IP Pin
ThatsAlok1-Jan-06 22:43
ThatsAlok1-Jan-06 22:43 
QuestionMSVC Your own toy os made EASY. Pin
kmcguire34131-Jan-06 21:17
kmcguire34131-Jan-06 21:17 
QuestionCD Write Pin
mehrdadov1-Jan-06 20:47
mehrdadov1-Jan-06 20:47 
AnswerRe: CD Write Pin
kakan2-Jan-06 1:07
professionalkakan2-Jan-06 1:07 
Questionplease help me (need help about class,pointers and etc) Pin
neodeaths1-Jan-06 20:44
neodeaths1-Jan-06 20:44 

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.