Is this a valid c++ code

Discussion in 'C++' started by birgir.sigurjonsson@roxar.com, Aug 18, 2006.

  1. Guest

    Hei, I am getting compile error on the following code snip:

    template <typename S> class Undef;

    template <typename S> class A {
    public:
    A() {}

    private:
    Undef<S> m_s;
    Undef < int > m_r;
    };

    void my_app() {
    // no references to either Undef or A
    // however a compiler-error on use of Undef<int>
    // but not on Undef<S>
    }

    I am getting the following error:

    The indicated type is incomplete.

    Undef < int > m_r;
    ^
    The error is generated on IRIX with MIPSpro Compilers: Version 7.30 and
    7.4.2m
    and
    g++ 3.4.* and 4.0.*

    It compiles fine on g++ 3.2, Solaris and Visiual Studio.

    So the question is, is this code valid and the compiler are wrong?

    Birgir Sigurjonsson.
    , Aug 18, 2006
    #1
    1. Advertising

  2. Kai-Uwe Bux Guest

    wrote:

    > Hei, I am getting compile error on the following code snip:
    >
    > template <typename S> class Undef;
    >
    > template <typename S> class A {
    > public:
    > A() {}
    >
    > private:
    > Undef<S> m_s;
    > Undef < int > m_r;
    > };
    >
    > void my_app() {
    > // no references to either Undef or A
    > // however a compiler-error on use of Undef<int>
    > // but not on Undef<S>
    > }
    >
    > I am getting the following error:
    >
    > The indicated type is incomplete.
    >
    > Undef < int > m_r;
    > ^
    > The error is generated on IRIX with MIPSpro Compilers: Version 7.30 and
    > 7.4.2m
    > and
    > g++ 3.4.* and 4.0.*
    >
    > It compiles fine on g++ 3.2, Solaris and Visiual Studio.
    >
    > So the question is, is this code valid and the compiler are wrong?


    I think the compiler is right and the code is invalid: the type Undef<int>
    is not dependent on the template parameter S. Therefore, namelookup for
    non-dependent names applies. That is, the compiler does not wait for the
    template to be instantiated, but looks around for declarations of
    Undef<int> that are vailable at the point it is used in the template A. At
    that point, however, Undef<int> is incomplete, hence the error.


    Best

    Kai-Uwe Bux
    Kai-Uwe Bux, Aug 18, 2006
    #2
    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. Replies:
    2
    Views:
    429
    Adam P. Jenkins
    Jan 18, 2005
  2. Eric Biller

    Embedding VRML-Objects in valid code

    Eric Biller, Nov 13, 2003, in forum: HTML
    Replies:
    6
    Views:
    3,732
    Toby A Inkster
    Nov 14, 2003
  3. Gianni Mariani

    is this code valid ?

    Gianni Mariani, May 17, 2004, in forum: C++
    Replies:
    5
    Views:
    352
    Gianni Mariani
    May 19, 2004
  4. Replies:
    64
    Views:
    1,223
    Dave Thompson
    Dec 20, 2004
  5. Any C code are valid C++ code?

    , Dec 10, 2004, in forum: C Programming
    Replies:
    67
    Views:
    1,140
    Dave Thompson
    Dec 20, 2004
Loading...

Share This Page