基本的なものが欠けているかどうかはわかりません。しかし、コンパイラがこのコードのエラーを生成している理由を理解できません。
class A
{
};
class B
{
public:
B();
A* get() const;
private:
A* m_p;
};
B::B()
{
m_p = new A;
}
A* B::get() const
{
//This is compiling fine
return m_p;
}
class C
{
public:
A* get() const;
private:
A m_a;
};
A* C::get() const
{
//Compiler generates an error for this. Why?
return &m_a;
}
編集:コンパイラエラーは次のとおりです:エラーC2440:'return':'const classA*'から'classA*'に変換できません変換は修飾子を失います