CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: how to do?

  1. #1
    Join Date
    Jan 2005
    Posts
    54

    Question 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...

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    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

  3. #3
    Join Date
    Jan 2005
    Posts
    54

    Smile Re: how to do?

    You are right. I think it too complicated. Thanks

  4. #4
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: how to do?

    Quote Originally Posted by gamecocks
    You are right. I think it too complicated. Thanks
    You should use the std::string instead of homegrown strings.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured