Re: Inheritance question
Jack wrote:
Problem identified: C2614
class cFile
{
public:
cFile() { }
cFile (std::string fileName, Mode aMode);
virtual ~cFile() { } // override for various types of files
public:
bool OpenFileEx (void);
protected:
Mode m_Mode;
std::string m_strFilename;
HANDLE m_hFile;
HANDLE m_hFileMapping;
};
class cTargetFile : public cFile
{
public:
cTargetFile() { }
~cTargetFile() { }
cTargetFile(std::string fileName, Mode aMode) : m_strFilename(fileName),
m_Mode(aMode) { }
^^^ this line C2614 m_Mode + m_strFilename is not a base or member
};
Jack:
This happens because m_strFileName and m_mode are indeed not bases or
members of cTargetFile - they are members of cFile.
You should pass these parameters to the base class constructor:
cTargetFile(const std::string& fileName, Mode aMode) :
cFile(fileName, aMode)
{
}
Note that I have changed the signature - don't pass objects like
std::string by value. If Mode is a complex object you should pass it by
cost reference also.
--
David Wilkinson
Visual C++ MVP