Vincent RICHOMME wrote:
Rolf Magnus a écrit :
Vincent RICHOMME wrote:
class Folder
{
public:
friend class PimItemCollection;
Folder(OutlookSession* pOutlookSession);
virtual PimItemCollection* get_Items();
protected:
bool GetPOOMFolder();
OutlookSession* m_pOutlookSession;
OlDefaultFolders m_eFolderType;
IFolderPtr m_pIFolder;
PimItemCollection* m_pContactCol;
};
class ContactFolder : public Folder
{
public:
// Constructor/destructor
ContactFolder(OutlookSession* pOutlookSession);
~ContactFolder();
virtual ContactCollection* get_Items();
private:
};
I have ContactFolder deriving from Folder.
But when I compile I got the following error :
System.WindowsMobile.PocketOutlook.cpp(107) : error C2614:
'System::WindowsMobile::PocketOutlook::ContactFold er' : illegal member
initialization: 'm_eFolderType' is not a base or member
ContactFolder::ContactFolder(OutlookSession* pOutlookSession)
: Folder(pOutlookSession),
m_eFolderType( olFolderContacts )
{
}
Well, the compiler is correct. m_eFolderType is a member of Folder, andso
it can only be initialized in the initializer list of Folder's constructor.
So if I need to change it, do I need to do it inside the constructor ?
No, at least not in the body of the constuctor. Your Folder class
needs to provide a constructor that initializes all of its members that
require initialization (including m_eFolderType), and then
ContactFolder must provide a constructor that calls the Folder
constructor in its initialization list. Let's take a simple example:
class Parent {
int i;
public:
Parent(int j) : i(j) {}
};
class Child : public Parent {
public:
// the following line is an ERROR:
// Child (int k) : i(k) {}
// the following line is the correct way to initialize Parent::i
Child(int k) : Parent(k) {}
};
Hope that helps.
Best regards,
Tom