I am trying to make use of some inherited class & function (e.g. class X, function abc()) from other parent classes (e.g. class A,B), unfortunately, I have got 'multiple definition' error whlie compliling.
//AAA.h
class A {
public :
virtualvoid abc();
}
class X : public A {
public :
void abc();
}
//AAA.cc
void X::abc() {
}
//BBB.h
class B {
public :
virtualvoid abc();
}
class X : public B {
public :
void abc();
}
//BBB.cc
void X::abc() {
}
how can I refer to the parent classes A,B while calling the abc() function?
If they derive from different classes and have different functions, it doesn't make much sense to give them the same names, now does it? And no, you can't refer to X like that, since it's being defined in the global scope. You could do this:
1 2 3 4 5
class A{
class X{
//...
};
};
But then you can't have it derive from A (I think).
The :: operator is used to refer to functions, variables, objects or classes defined in a class or namespace, not to do what you did there. There can only be one unique identifier (although functions have a different rule in C++) in each namespace, so that syntax wouldn't be that useful, anyway.