Multiple Definition Error

Hi,

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//AAA.h
class A {
public :
virtual void abc();
}

class X : public A {
public :
void abc();
}

//AAA.cc
void X::abc() {
}

//BBB.h
class B {
public :
virtual void 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?

Thank you for any clue..
J
You're defining X twice. One derives from A and the other from B.
Last edited on
But in the case, i need to define X twice for different A and B (some functions in X may be different).

Is it possible to call the abc() function something like...

void A::X::abc() {}

Thank you for your answer.
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.
Last edited on
Topic archived. No new replies allowed.