private inheritance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aleksandr Rulev

    private inheritance

    #include <iostream>

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

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

    };

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

    };

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

    };

    main (){
    FooTooBar x;
    }

    should x be instantiated o should it give compiler error?


  • WW

    #2
    Re: private inheritance

    Aleksandr Rulev wrote:[color=blue]
    > #include <iostream>
    >
    > class Foo{
    > public:
    > Foo(){std::cout <<"Foo ";};
    > };
    >
    > class Bar:Foo{
    > public:
    > Bar(){std::cout <<"Bar ";};
    >
    > };
    >
    > class FooToo: virtual Foo{
    > public:
    > FooToo(){std::c out<<"FooToo ";};
    >
    > };
    >
    > class FooTooBar: virtual FooToo,virtual Bar{
    > public:
    > FooTooBar(){std ::cout<<"FooToo Bar ";};
    >
    > };
    >
    > main (){
    > FooTooBar x;
    > }
    >
    > should x be instantiated o should it give compiler error?[/color]

    Why do you think it should be an error?

    --
    WW aka Attila


    Comment

    • WW

      #3
      Re: private inheritance

      Aleksandr Rulev wrote:[color=blue]
      > main (){[/color]

      int main() {

      --
      WW aka Attila


      Comment

      • Aleksandr Rulev

        #4
        Re: private inheritance

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


        "WW" <wolof@freemail .hu> wrote in message
        news:bln0pu$d58 $1@phys-news1.kolumbus. fi...[color=blue]
        > Aleksandr Rulev wrote:[color=green]
        > > #include <iostream>
        > >
        > > class Foo{
        > > public:
        > > Foo(){std::cout <<"Foo ";};
        > > };
        > >
        > > class Bar:Foo{
        > > public:
        > > Bar(){std::cout <<"Bar ";};
        > >
        > > };
        > >
        > > class FooToo: virtual Foo{
        > > public:
        > > FooToo(){std::c out<<"FooToo ";};
        > >
        > > };
        > >
        > > class FooTooBar: virtual FooToo,virtual Bar{
        > > public:
        > > FooTooBar(){std ::cout<<"FooToo Bar ";};
        > >
        > > };
        > >
        > > main (){
        > > FooTooBar x;
        > > }
        > >
        > > should x be instantiated o should it give compiler error?[/color]
        >
        > Why do you think it should be an error?
        >
        > --
        > WW aka Attila
        >
        >[/color]


        Comment

        • Aleksandr Rulev

          #5
          Re: private inheritance

          main() = int main(). you should know.
          "WW" <wolof@freemail .hu> wrote in message
          news:bln0ql$d7e $1@phys-news1.kolumbus. fi...[color=blue]
          > Aleksandr Rulev wrote:[color=green]
          > > main (){[/color]
          >
          > int main() {
          >
          > --
          > WW aka Attila
          >
          >[/color]


          Comment

          • WW

            #6
            Re: private inheritance

            Aleksandr Rulev wrote:[color=blue]
            > MS C++ compiles it; Borland doesn't. What is proper behavior? (I
            > don't trust MS implementation)[/color]

            Do not top post. What error do you get?

            --
            WW aka Attila


            Comment

            • WW

              #7
              Re: private inheritance

              Aleksandr Rulev wrote:[color=blue]
              > main() = int main(). you should know.[/color]

              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++.

              --
              WW aka Attila


              Comment

              • Aleksandr Rulev

                #8
                Re: private inheritance

                Foo()::Foo() is not accessible. // Borland
                OK with MS
                "WW" <wolof@freemail .hu> wrote in message
                news:bln1g5$fck $1@phys-news1.kolumbus. fi...[color=blue]
                > Aleksandr Rulev wrote:[color=green]
                > > MS C++ compiles it; Borland doesn't. What is proper behavior? (I
                > > don't trust MS implementation)[/color]
                >
                > Do not top post. What error do you get?
                >
                > --
                > WW aka Attila
                >
                >[/color]


                Comment

                • Aleksandr Rulev

                  #9
                  Re: private inheritance


                  "WW" <wolof@freemail .hu> wrote in message
                  news:bln1ka$fmk $1@phys-news1.kolumbus. fi...[color=blue]
                  > Aleksandr Rulev wrote:[color=green]
                  > > main() = int main(). you should know.[/color]
                  >
                  > 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++.
                  >
                  > --
                  > WW aka Attila
                  >
                  >[/color]

                  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.


                  Comment

                  • WW

                    #10
                    Re: private inheritance

                    Aleksandr Rulev wrote:[color=blue]
                    > Foo()::Foo() is not accessible. // Borland
                    > OK with MS[/color]

                    Do not top post:


                    --
                    WW aka Attila


                    Comment

                    • WW

                      #11
                      Re: private inheritance

                      Aleksandr Rulev wrote:[color=blue]
                      > it says that a compiler is not required to
                      > implement the implicit int rule.[/color]

                      Nope. It does not even mention this rule.
                      [color=blue]
                      > That means you cannot rely on this feature in
                      > portable code.[/color]



                      --
                      WW aka Attila


                      Comment

                      • Jonathan Mcdougall

                        #12
                        Re: private inheritance

                        > > Aleksandr Rulev wrote:[color=blue][color=green][color=darkred]
                        > > > main() = int main(). you should know.[/color]
                        > >
                        > > 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++.
                        > >
                        > > --
                        > > WW aka Attila
                        > >
                        > >[/color]
                        >
                        > 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.[/color]

                        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


                        Comment

                        • Default User

                          #13
                          Re: private inheritance

                          Aleksandr Rulev wrote:[color=blue]
                          >
                          > main() = int main(). you should know.[/color]


                          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

                          Comment

                          • Ralf Schneeweiß

                            #14
                            Re: private inheritance

                            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.


                            I will look to the standard to find it out.


                            Ralf



                            Seminare zur Softwareentwicklung, Coaching und Projektarbeit



                            Comment

                            • Jerry Coffin

                              #15
                              Re: private inheritance

                              In article <B4Efb.169264$3 o3.12311887@bgt nsc05-
                              news.ops.worldn et.att.net>, a.rulev@worldne t.att.net says...

                              [ ... ]
                              [color=blue]
                              > 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.[/color]

                              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.

                              --
                              Later,
                              Jerry.

                              The universe is a figment of its own imagination.

                              Comment

                              Working...