c++ - Finding errors in a code snippet -
i asked find errors in next code. there apparently 5 errors, have found 3 of them far, here code
#include <iostream> class base{ public: base(int data) : _data(data){} virtual void printdata(){ std::cout << "base " << _data << std::endl; } private: int _data; }; class derived : public base{ public: derived(derivdata) : base(derivdata){} void printdata(){ std::cout << "derived " << _data << std::endl; } } int main(){ derived *var = new derived(5); var->printdata(); base* basevar = static_cast<base>(*var); basevar->printdata(); }
the class derived
not end semi colon. the argument of derived
constructor not declared type the info fellow member of base
pivate cannot accessed in derived
beingness attempted. i struggling find others, suspect casting in main()
don't yet know much casting. appreciate help in right direction. thanks
base* basevar = static_cast<base>(*var);
this should be
base* basevar = static_cast<base*>(var);
c++ debugging
No comments:
Post a Comment