Thread: Copy Constructor with classmember CArray

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    7

    Copy Constructor with classmember CArray

    I keep getting C2248 error messages in Visual Studio 2005. I have solved previous problems with this error, by creating an copy constructor for CMapLayer. The program is displaying and changing an SVG map. I have CMapLegend, CMapCategory and CMapLayer. These classes represent a legend for a map. The layers of the map are divided into categories.

    For drawing the map I have:
    Code:
    for(int iCount1 = 0; iCount1 < Categories.GetSize(); iCount1++) {  		
      CreateCategory(Categories.GetAt(iCount1));    		
      for(int   iCount2 = 0; iCount2 < Categories.GetAt(iCount1).GetNumberOfLayers(); iCount2++) {  			
        CreateLayer(Categories.GetAt(iCount1).GetLayerByIndex(iCount2));  		
      }  	
    }
    inside CMapLegend::CreateLegend();
    Code:
    class CMapLegend  
    {  
    public:  	
      CMapLegend(void);  	
      ~CMapLegend(void);  	
      void CreateLegend(void);  	
      void SetVisible(void);  	
      void SetInvisible(void); 
    private:  	
      eSVG::CActiveXeSVG svgControl;  	
      CArray<CMapCategory, CMapCategory> Categories;
      CString sSvgId;	
      eSVG::CElement CreateLayer(CMapLayer& mapLayer); 
      eSVG::CElement CreateCategory(CMapCategory& mapCategory);  
    };
    Code:
    class CMapLayer  
    {  
    public:	  	
      CMapLayer(CString sName, CString sSvgId, CString sIconRef, bool bDisplay);	  	
      CMapLayer(void);  	
      CMapLayer(const CMapLayer& mapLayer);  
      CMapLayer operator=(const CMapLayer& mapLayer);  	
      ~CMapLayer(void);  	
      void SetVisible(void);  	
      void SetInvisible(void);  	
      CString GetName(void);  	
      CString GetSvgId(void);  	
      CString GetIconRef(void);  	
      bool GetDisplay(void);  
    protected:  	
      eSVG::CActiveXeSVG svgControl;  	 
      CString sName;  	
      CString sSvgId;  	
      CString sIconRef;  	
      bool bDisplay;		 
    };
    Code:
    class CMapCategory : public CMapLayer 
    { 
    public:  	
      CMapCategory(void);  	
      CMapCategory(const CMapCategory& mapCategory);	  	
      ~CMapCategory(void);  	
      CMapCategory operator =(const CMapCategory& mapCategory);  	
      void SetLayersVisible(void);  	
      void SetLayersInvisible(void);  	
      void AddLayer(const CMapLayer& mapLayer);  	
      CMapLayer GetLayerById(void);	  	
      int GetNumberOfLayers(void);  	
      CMapLayer GetLayerByIndex(int index);  
    private:  	
      bool bExpanded;	  	
      CArray<CMapLayer, CMapLayer> Layers;	  
    };

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    So where are you getting the error? If something is accessing a private member then check the definitions for all the functions you're using at the error point. Also where is GetAt() defined?
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    7
    Error 1 error C2248: 'CObject:perator =' : cannot access private member declared in class 'CObject' C:\Program Files\Microsoft Visual Studio 8\VC\ce\atlmfc\include\afxtempl.h 324

    The error occurs in CObject of MFC. GetAt is a CArray method for getting an object inside the CArray at a given position.

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    7
    When I uncomment the CArray lines in following code: the error doesn't occur, so those are the lines:
    Code:
    CMapCategory::CMapCategory(const CMapCategory& mapCategory)  {  	
      this->sIconRef  = mapCategory.sIconRef;  	
      this->sName     = mapCategory.sName;  	
      this->sSvgId    = mapCategory.sSvgId;  	
      this->bDisplay  = mapCategory.bDisplay;  	
      this->bExpanded = mapCategory.bExpanded;  	
      //this->Layers    = mapCategory.Layers;	  
    }    
    CMapCategory CMapCategory::operator =(const CMapCategory& mapCategory)  {  	
      CMapCategory newCategory;  	
      newCategory.sIconRef  = mapCategory.sIconRef;  	  
      newCategory.sName     = mapCategory.sName;  	
      newCategory.sSvgId    = mapCategory.sSvgId;  	
      newCategory.bDisplay  = mapCategory.bDisplay;  
      newCategory.bExpanded = mapCategory.bExpanded;  
      //newCategory.Layers    = mapCategory.Layers;  
      return newCategory;  }
    Layers is a CArray<CMapLayers, CMapLayers>.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You are not allowed to copy a CArray like that. Use the Copy member function instead.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copying constant amount of data
    By TriKri in forum C++ Programming
    Replies: 16
    Last Post: 07-12-2008, 06:32 AM
  2. calling copy constructor from template
    By Ancient Dragon in forum C++ Programming
    Replies: 3
    Last Post: 09-28-2005, 01:54 PM
  3. dynamic memory alloccation & returning objects
    By haditya in forum C++ Programming
    Replies: 8
    Last Post: 04-21-2005, 11:55 PM
  4. Copy constructors and operator=()
    By filler_bunny in forum C++ Programming
    Replies: 13
    Last Post: 08-25-2003, 07:43 AM
  5. Copy Constructor Help
    By Jubba in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2001, 11:15 AM