What(s wrong with that :

R

Rolf Magnus

Vincent said:
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::ContactFolder' : 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, and so
it can only be initialized in the initializer list of Folder's constructor.
 
V

Vincent RICHOMME

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::ContactFolder' : illegal member
initialization: 'm_eFolderType' is not a base or member


ContactFolder::ContactFolder(OutlookSession* pOutlookSession)
: Folder(pOutlookSession),
m_eFolderType( olFolderContacts )
{

}
 
V

Vincent RICHOMME

Rolf Magnus a écrit :
Well, the compiler is correct. m_eFolderType is a member of Folder, and so
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 ?
 
T

Thomas Tutone

Vincent said:
Rolf Magnus a écrit :

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
 
T

Thomas Tutone

Thomas Tutone wrote:

[snip]
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 {

Although this example is correct, to make it more similar to your class
definition, add the following line here:

protected:
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) {}
};

Also, note that many people would advise you to use private, rather
than protected, data members in your parent class. The FAQ discusses
the issue (although takes a more permissive stance on the subject):

http://www.parashift.com/c++-faq-lite/basics-of-inheritance.html#faq-19.8

But in any case, you can see that making the member protected does not
offer any advantage with respect to initialization lists.

Best regards,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top