private inheritance

  • Thread starter Aleksandr Rulev
  • Start date
A

Aleksandr Rulev

#include <iostream>

class Foo{
public:
Foo(){std::cout<<"Foo ";};
};

class Bar:Foo{
public:
Bar(){std::cout<<"Bar ";};

};

class FooToo: virtual Foo{
public:
FooToo(){std::cout<<"FooToo ";};

};

class FooTooBar: virtual FooToo,virtual Bar{
public:
FooTooBar(){std::cout<<"FooTooBar ";};

};

main (){
FooTooBar x;
}

should x be instantiated o should it give compiler error?
 
W

WW

Aleksandr said:
#include <iostream>

class Foo{
public:
Foo(){std::cout<<"Foo ";};
};

class Bar:Foo{
public:
Bar(){std::cout<<"Bar ";};

};

class FooToo: virtual Foo{
public:
FooToo(){std::cout<<"FooToo ";};

};

class FooTooBar: virtual FooToo,virtual Bar{
public:
FooTooBar(){std::cout<<"FooTooBar ";};

};

main (){
FooTooBar x;
}

should x be instantiated o should it give compiler error?

Why do you think it should be an error?
 
A

Aleksandr Rulev

MS C++ compiles it; Borland doesn't. What is proper behavior? (I don't trust
MS implementation)
 
W

WW

Aleksandr said:
main() = int main(). you should know.

Nope. You should *not* know. Neither in C++ nor in current C (C99)
implicit int is legal. It has never been part of standard C++.
 
A

Aleksandr Rulev

WW said:
Nope. You should *not* know. Neither in C++ nor in current C (C99)
implicit int is legal. It has never been part of standard C++.

it says that a compiler is not required to
implement
the implicit int rule. That means you cannot rely on this feature in
portable
code.
 
J

Jonathan Mcdougall

Aleksandr said:
it says that a compiler is not required to
implement
the implicit int rule. That means you cannot rely on this feature in
portable
code.

That is the definition of "standard code". Implicit ints are not standard
(not portable) and are implementation-defined.

The thing is, this newsgroup is about Standard C++, not about
implementation-
defined features.


Jonathan
 
D

Default User

Aleksandr said:
main() = int main(). you should know.


Don't top-post. Your replies belong following properly trimmed quotes.

Your assertion is wrong. In C, before the latest standard, that was
true. It has never been true in standard C++.




Brian Rodenborn
 
R

Ralf Schneeweiß

I think, that your problem is very intresting because of the private virtual
inheritance.
I guess, with the class Bar there is no conflict, because its base class
constructor is
called inside the initialization list implicitly.
With the virtual inheritance you have to repeat an initialization in later
class generations.
The question is now: is the default constructor implicitly reachable from
second and third
class generations or not, if the zero generation is inherited private?

The Comeau compiler gives no error messages.
http://www.comeaucomputing.com/tryitout/

I will look to the standard to find it out.


Ralf



http://www.oop-trainer.de
 
J

Jerry Coffin

[ ... ]
it says that a compiler is not required to
implement
the implicit int rule. That means you cannot rely on this feature in
portable
code.

Not so -- what it says is ($7.1.5/2): "At least one type-specifier that
is not a cv-qualifier is required in a declaration unless it declares a
constructor, destructor or conversion function."

That means that any code that tries to use the old implicit int rule
from C is _ill-formed_, which is the terminology the C++ standard uses
signify all those possible input files that aren't C++ programs, so a
properly functioning C++ compiler is required to diagnose them as being
in error.
 

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

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top