nested class forward declaration

Discussion in 'C++' started by n.torrey.pines@gmail.com, Feb 28, 2007.

  1. Guest

    I'm curious, is this legal C++ ? `g++ -pedantic -ansi -Wall` gives no
    warnings.

    struct s {
    char c;
    s(char c) : c(c) {}
    void f() const;
    private:
    struct i; // !!!
    };

    struct s::i {
    float f;
    i() : f(0) {}
    };

    void s::f() const {
    i ii;
    std::cout << ii.f << c << '\n';
    }
    , Feb 28, 2007
    #1
    1. Advertising

  2. wrote:
    > I'm curious, is this legal C++ ? `g++ -pedantic -ansi -Wall` gives no
    > warnings.
    >
    > struct s {
    > char c;
    > s(char c) : c(c) {}
    > void f() const;
    > private:
    > struct i; // !!!
    > };
    >
    > struct s::i {
    > float f;
    > i() : f(0) {}
    > };
    >
    > void s::f() const {
    > i ii;
    > std::cout << ii.f << c << '\n';
    > }


    Yes, it is. Why wouldn't it be legal?

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Feb 28, 2007
    #2
    1. Advertising

  3. Marcus Kwok Guest

    wrote:
    > I'm curious, is this legal C++ ? `g++ -pedantic -ansi -Wall` gives no
    > warnings.
    >
    > struct s {
    > char c;
    > s(char c) : c(c) {}
    > void f() const;
    > private:
    > struct i; // !!!
    > };
    >
    > struct s::i {
    > float f;
    > i() : f(0) {}
    > };
    >
    > void s::f() const {
    > i ii;
    > std::cout << ii.f << c << '\n';
    > }


    FWIW, Comeau online compiled it with no errors in strict mode either.

    --
    Marcus Kwok
    Replace 'invalid' with 'net' to reply
    Marcus Kwok, Feb 28, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. E11
    Replies:
    1
    Views:
    4,743
    Thomas Weidenfeller
    Oct 12, 2005
  2. qazmlp
    Replies:
    1
    Views:
    596
    Jonathan Turkanis
    Feb 15, 2004
  3. Stephane Routelous
    Replies:
    5
    Views:
    17,090
    Gianni Mariani
    Feb 19, 2004
  4. Jiri Palecek
    Replies:
    2
    Views:
    4,554
    Jonathan Turkanis
    Jul 26, 2004
  5. Susan Baker
    Replies:
    1
    Views:
    376
    Victor Bazarov
    Jul 7, 2005
Loading...

Share This Page