|
-
January 20th, 2005, 02:20 PM
#1
how to do?
Code:
class myClass
{
public:
myClass();
myClass(myClass&);
myClass& operator = (myClass&);
mySubClass * pSubClass
const char* getName();
void setName(const char*);
int getValue();
void setValue(int);
private:
char* szName;
int nValue;
}
myClass::myClass()
{
szName=new char[16];
strcpy(szName,"unknown");
nValue=-1;
pSubClass=new mySubClass;
return;
}
myClass::myClass(myClass& CValue)
{
szName=new char[16];
strcpy(szName,CValue.getName());
nValue=CValue.getValue();
pSubClass=new mySubClass;
pSubClass=CValue.pSubClass;
return;
}
myClass::myClass::operator=(myClass& CValue)
{
szName=new char[16];
strcpy(szName,CValue.getName());
nValue=CValue.getValue();
pSubClass=new mySubClass;
pSubClass=CValue.pSubClass;
return *this;
}
myClass::~myClass()
{
delete [] szName;
delete pSubClass;
return;
}
class mySubClass
{
public:
mySubClass();
mySubClass(mySubClass&);
mySubClass& operator = (mySubClass&);
const char* getName();
void setName(const char*);
int getValue();
void setValue(int);
private:
char* szName;
int nValue;
}
mySubClass::mySubClass()
{
szName=new char[16];
strcpy(szName,"unknown");
nValue=-1;
return;
}
mySubClass::mySubClass(mySubClass& CValue)
{
szName=new char[16];
strcpy(szName,CValue.getName());
nValue=CValue.getValue();
return;
}
mySubClass::mySubClass::operator=(mySubClass& CValue)
{
szName=new char[16];
strcpy(szName,CValue.getName());
nValue=CValue.getValue();
return *this;
}
mySubClass::~mySubClass()
{
delete [] szName;
return;
}
other member function.
void myFunction(myClass&CValue)//fill CValue
{
}
int main(int argc, char* argv[])
{
class myClass CMyClass;
myFunction(CMyClass);
return 0;
}
Why I get Debug error: DAMAGE after normal block(#66) at 0x00894120? What is wrong with it? How to fix it? Thanks
Last edited by Andreas Masur; January 20th, 2005 at 05:03 PM.
Reason: Added code tags...
-
January 20th, 2005, 03:14 PM
#2
Re: how to do?
It's very difficult to read this without code tags.
However, without the implementation of "myFunction", I can only guess that you are trying to copy strings into the 'szName' member(s) that are larger then 16 characters.
Viggy
-
January 20th, 2005, 05:08 PM
#3
Re: how to do?
You are right. I think it too complicated. Thanks
-
January 21st, 2005, 02:10 AM
#4
Re: how to do?
 Originally Posted by gamecocks
You are right. I think it too complicated. Thanks
You should use the std::string instead of homegrown strings.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|