class a
{
protected:
const int _ID;
public:
a::a(int id){};
a::top(int num);
};
class b : public a
{
static int ok;
b::b(int id):a(id){};
a::top(ok);
}
int main()
{
int t=5;
b opj=b(t);
}
first why i get this compile error that solved only when i remove the const
non-static const member ‘const int Student::_ID’, can’t use default assignment operator –
instantiated from ‘void std::vector::_M_insert_aux(__gnu_cxx::__normal_iterator, const _Tp&) [with _Tp = Student, _Alloc = std::allocator]’
second
i have anther problem
undefined reference to b::ok
Second first:
b::okhas been declared, but not defined. Someplace, (preferably b.cpp), you need to add:As for your first problem,
_IDis const, it value cannot be changed — but, you never give it a value to start with. You have to assign it an initial value:Now, you really should defined _ID as well, as we did with b::ok, but since it is
const, the compiler may let you get away without doing that (some conditions apply).