Is this a valid c++ code

  • Thread starter birgir.sigurjonsson
  • Start date
B

birgir.sigurjonsson

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

Kai-Uwe Bux

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
 

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

Similar Threads

Is this valid c++? 10
Is this valid C++ code? 6
is this valid c++? 3
Is this syntactically valid C++? 5
How to try a range of hex values in C# code ? 0
Valid C++? 6
Is this valid C++ ? 5
is this code valid ? 5

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top