copy constructor 
Author Message
 copy constructor

Hey.. We have a class :

class CGlueImage : public CObject
{
 DECLARE_DYNCREATE(CGlueImage)

// Attributes
public:
 CGlueImage();
 CGlueImage(CString navn, int id);

// Operations
public:
 CString GetGlueName();
 int GetGlueId();
 CRect GetRect();
 void DrawDragImage(CDC* pDC, POINT point);
 void DrawHover(CDC *pDC, POINT point);
 BOOL PtInImage(POINT point);
 UINT GetWidth();
 void SetWidth(UINT width);
 void Draw(CDC *pDC, int x, int y);

// Overrides
 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CGlueImage)
 //}}AFX_VIRTUAL
 CGlueImage& operator=(const CGlueImage& rhs)
 {
  m_color = RGB(GetRValue(rhs.m_color), GetGValue(rhs.m_color),
GetBValue(rhs.m_color));
  m_glueRect = CRect(rhs.m_glueRect.TopLeft(),
rhs.m_glueRect.BottomRight());
  m_nGlueHeight = rhs.m_nGlueHeight;
  m_nGlueId = rhs.m_nGlueId;
  m_sGlueName = rhs.m_sGlueName;
  return *this;
 }
 CGlueImage(const CGlueImage& rhs)
 {
  m_color = rhs.m_color;
  m_glueRect = rhs.m_glueRect;
  m_nGlueHeight = rhs.m_nGlueHeight;
  m_nGlueId = rhs.m_nGlueId;
  m_sGlueName = rhs.m_sGlueName;
 }

 ~CGlueImage();

// Implementation
protected:

 COLORREF m_color;
 CRect m_glueRect;
 UINT m_nGlueHeight;
 int m_nGlueId;
 CString m_sGlueName;

 // Generated message map functions
 //{{AFX_MSG(CGlueImage)
  // NOTE - the ClassWizard will add and remove member functions here.
 //}}AFX_MSG

Quote:
};

In our View we have :

std::vector<CGlueImage> m_glueList;

and a method :

void CGlueView::AddImage(CString name, int id)
{
  CGlueImage gi(name, id);
  m_glueList.push_back(gi);
  Invalidate();

Quote:
}

What we are trying to do is use the AddImage method in the documents
OnNewDocument method:

  CMainFrame* pMainFrame = (CMainFrame*)AfxGetApp()->GetMainWnd() ;
  CGlueView* pGlueView =
(CGlueView*)pMainFrame->m_wndGlueBar.GetRuntimeClass();
   pGlueView->AddImage("NADA", 0);

But when we try to make a new document in our program (aka OnNewDocument()
is run) this happens :

Unhandled exception in Program.exe (MFC42D.DLL) : 0xC000005 : Acces
Violation.

Cotext i de{*filter*} :
CObject::CObject()
CGlueImage::CGlueImage(const CGlueImage &)
std::_Construct(CGlueImage *, const CGlueImage &)
std::allocator<CGlueImage>::construct(CGlueImage *, const CGlueImage &)
std::vector<CGlueImage, std::allocator<CGlueImage> >::_Ufill(CGlueImage *,
unsigned int, const CGlueImage &)
std::vector>CGlueImage, std::allocator<CGlueImage> >::insert(CGlueImage *,
unsigned int, const CGlueImage &)
std::vector<CGlueImage, std::allocator<CGlueImage> >::insert(CGlueImage*,
const CGlueImage &)
std::vector<CGlueImage, std::allocator<CGlueImage> >::push_back(const
CGlueImage&)
CGlueView::AddImage(CString, int)

It seems like theres a problem with CGlueImages copy constructor, but what ?
I spent last night trying all sorts of ideas I could come up with, but now
Im lost.
I hope someone here have some ideas of what could cause this problem.

Cheers.
Thomas Ree Hjelm



Tue, 08 Nov 2005 23:00:37 GMT  
 copy constructor
Quote:
> It seems like theres a problem with CGlueImages copy constructor, but what

?

Actually I dont think its the copy constructor after all. Cause I tried to
use the
same method, AddImage(...), from within its own class (CGlueView) and there
where no errors. So the problem only occurs when I try to use the method
from
the Document. Any ideas why anyone ?

Cheers.
Thomas Ree Hjelm



Tue, 08 Nov 2005 23:04:09 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Copy Constructor : Copying Base Class Member Variables

2. destructor is called before copy-constructor on temporary class (allocated on stack during function call)

3. Copy Constructor with pointer as parameter??

4. Exception gurus - Copy constructors of exceptions

5. Copy Constructor Question

6. Union Member Cannot Have Copy Constructor

7. Function return invokes copy constructor?

8. function return invokes copy constructor?

9. Copy constructors

10. private copy constructors

11. Unneccessary copy-constructor calls?

12. Too many copy constructors

 

 
Powered by phpBB® Forum Software