weiß jemand, warum dies einen Compilerfehler gibt? Ich habe versucht, VS 2005 und Codewarrior:Referenz auf Zeiger und C++ Polymorphismus
class Parent {
protected:
int m_Var;
public:
Parent() : m_Var(0) {}
virtual ~Parent() {}
void PubFunc();
};
class Child : public Parent {
protected:
bool m_Bool;
public:
Child() : m_Bool(false) {}
virtual ~Child() {}
void ChildFunc();
};
void RemoveObj(Parent *& ppObj)
{
delete ppObj;
ppObj = 0;
}
int main()
{
Parent* pPObj = 0;
Child* pCObj = 0;
pPObj = new Parent();
pCObj = new Child();
RemoveObj(pPObj);
RemoveObj(pCObj);
return 1;
}
Visual Studio sagt:
refptr.cpp (33): Fehler C2664: 'RemoveObj': kann nicht Parameter 1 aus konvertieren 'Child *' zu 'Eltern * &'
Dank
Schöne Argumentation. +1 :) –