Small inheritance problem.

M

mihai

I have a situation witch is like this:

// A.h
class A
{
class AA
{
};
};

// B.h
class B
{
class BB : public A::AA
{
BB();
};
};

// B.cpp
B::BB::BB() : A::AA(args)
{
}

The compiler error is: multiple definition of BB()
when I try to implement the constructor.

Have a nice day,
Mihai.
 
V

Victor Bazarov

mihai said:
I have a situation witch is like this:

// A.h
class A
{
class AA
{
};
};

// B.h
class B
{
class BB : public A::AA
{
BB();
};
};

// B.cpp
B::BB::BB() : A::AA(args)

Add 'inline' before this function.
{
}

The compiler error is: multiple definition of BB()
when I try to implement the constructor.

When you define a function in the header and include that header
in more than one translation unit, you get multiple definitions.
Instead, you should define the function in only one translation
unit or declare it 'inline'.

V
 
M

mihai

Thank you for your answer.
I have fixed this up. But there is another problem on MVC 6.0 it seems
that the cod does not compile, and with gcc 3.4 it works. I don't see
how this can be. There are both standard compilers, no?
 
I

iceColdFire

Hi,

Yes...MSVC 6.0 and gcc 3.4 are both standard compilers...however their
individual conformance to ISO C++ standards varies...MSVC 6.0 is 8
years old...so the compiler conformance to C++ standard dates back to
that time...maybe this particuar case was not included in affirmatives
part of standard so it gives compiler error...however gcc 3.4 follows
more latest c++ standrads and thus enables successfull compilation...

Just an issues of which standard is followed by compiler...thus use
latest compiler...GNU based gcc for *NIX and *NUX or cygwin mingw for
*dows is good...

Thanks
a.a.cpp
 
S

Samee Zahur

Yes...MSVC 6.0 and gcc 3.4 are both standard compilers...however
their
individual conformance to ISO C++ standards varies...MSVC 6.0 is 8
years old...

Indeed, AFAIK the ISO C++ standard was published for the first at
around the same time, so it's rather a big(!) ask for MSVC 6.0 to
conform to it when even the later versions are not that good at it :(

Samee
 
G

Ganesh

Isn't it class AA is private inner class of A and call to A::AA
should give compiler error ?

Thasks
Ganesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top