Cannot create array or vector of CPngImage class

241 Views Asked by At

I am using MFC Visual Studio 8 Version 9. I want to create an array or vector of CPngImage objects. If i declare the array to be global, its fine. If i try to add the array to one of my own classes in get the following error:

afxwin.h(312) : error C2248: 'CObject::CObject' : cannot access private member declared in class 'CObject'

Here is an example of what i am trying to do:

#pragma once
#include <list>
#include <vector>
#include <iterator>
#include <afxtoolbarimages.h>
#include <afxwin.h>

using namespace std;
#define MAX_IMAGES 30

class PayAppReport
{
private:

CString m_projectName;
CString m_address;
CString m_city;
CString m_county;
CString m_GCcontact;
CString m_weather;
vector<CString> m_contractorsOnSite;
vector<CString> m_workInPlace;
vector<CString> m_workProjected;
vector<CString> m_issues;
vector<CString> m_report;

CPngImage pngImage[MAX_IMAGES];

float m_amount;

int m_payapp,zipCode,currentLine;

COleDateTime m_start,m_stop,m_observation;

bool m_OnSchedule;

CRect printRect;

public:
    vector<CString> m_pictures;
    PayAppReport(void);
    ~PayAppReport(void);
    void Clear();
    void SetProjectName(CString name);
    CString GetProjectName();
    void SetAddress(CString name);
    CString GetAddress();
    void SetCity(CString name);
    CString GetCity();
    void SetCounty(CString name);
    void SetCounty(int zipCode);
    CString GetCounty();
    void SetGCcontact(CString name);
    CString GetGCcontact();
    void SetAmount(float dollars);
    float GetAmountFloat();
    CString GetAmountString();
    void SetPayAppNumber(int num);
    int GetPayAppNumber();
    void SetZipCode(int code);
    int GetZipCode();
    void SetOnSchedule(bool ans);
    bool OnSchedule();
    void SetStartDate(COleDateTime date);
    void SetCompletionDate(COleDateTime date);
    void SetObservationDate(COleDateTime date);
    COleDateTime GetStartDate();
    COleDateTime GetCompletionDate();
    COleDateTime GetObservationDate();
    void AddContractorsOnSite(CString name);
    void AddWorkInPlace(CString name);
    void AddWorkProjected(CString name);
    void AddIssues(CString name);
    void AddPictures(CString name);
    int GetNumberOfContractorsOnSite();
    int GetNumberOfWorkInPlace();
    int GetNumberOfWorkProjected();
    int GetNumberOfIssues();
    int GetNumberOfPictures();
    CString GetContractorsOnSite(int num);
    CString GetContractorsOnSite();
    CString GetWorkInPlace(int num);
    CString GetWorkProjected(int num);
    CString GetIssues(int num);
    CString GetWorkInPlace();
    CString GetWorkProjected();
    CString GetIssues();
    CString GetPictures(int num);
    void SetWeather(CString name);
    CString GetWeather();
    CString PutList(vector<CString> theList);
    void InitializeContractorsOnSite();
    void InitializeWorkInPlace();
    void InitializeWorkProjected();
    void InitializeIssues();
    void InitializePictures();
    void PutLine(CString rightText, CString leftText, CDC *pDC, HDC hDC, bool indent, int height);
    CString toCurrency(float val);
};

Can someone explain why i cannot do this?

1

There are 1 best solutions below

2
On

CObject is not designed with value semantics. Thus the copy constructor of CObject is marked as private. Thus declaring an array of CObject -- or an array of something derived from CObject like CPngImage -- is not the way to go.

Change your array to hold pointers, not whole objects (i.e. CPngImage* instead of CPngImage). See if that helps.

(Did you even take a look at the declaration of the class before asking this question?)