gcc, visual studio and dependent names

M

mojmir

Good morning,

i found small difference between gcc and visual studio when looking up
a
dependent name. Consider:

struct Base {
template<typename T, typename U>
void Implement (T t) { }
};

template<typename T, class BaseT>
struct Derived : BaseT {
template<typename U, typename V>
void foo (U u) {
//Implement<U,V>(u); // vs8, vs9 ok, gcc 3+ error
this->template Implement<U,V>(u); // vs ok, gcc ok
}
};

int main() {
Derived<int, Base> b;
b.foo<float, long>(1.0f);
}

It seems to me that gcc is right, because according standard the
Implement
method is a dependent name and therefore has to be accessed using this-
, hasn't it?

Mojmir
 
A

Alan Woodland

mojmir said:
Good morning,

i found small difference between gcc and visual studio when looking up
a
dependent name. Consider:

struct Base {
template<typename T, typename U>
void Implement (T t) { }
};

template<typename T, class BaseT>
struct Derived : BaseT {
template<typename U, typename V>
void foo (U u) {
//Implement<U,V>(u); // vs8, vs9 ok, gcc 3+ error
this->template Implement<U,V>(u); // vs ok, gcc ok
}
};

int main() {
Derived<int, Base> b;
b.foo<float, long>(1.0f);
}

It seems to me that gcc is right, because according standard the
Implement
method is a dependent name and therefore has to be accessed using this-
http://womble.decadentplace.org.uk/c++/template-faq.html#two-phase has
some information on this.

Alan
 
B

Bo Persson

mojmir wrote:
:: Good morning,
::
:: i found small difference between gcc and visual studio when
:: looking up a
:: dependent name. Consider:
::
:: struct Base {
:: template<typename T, typename U>
:: void Implement (T t) { }
:: };
::
:: template<typename T, class BaseT>
:: struct Derived : BaseT {
:: template<typename U, typename V>
:: void foo (U u) {
:: //Implement<U,V>(u); // vs8, vs9 ok, gcc 3+
:: error this->template Implement<U,V>(u); // vs ok, gcc ok
:: }
:: };
::
:: int main() {
:: Derived<int, Base> b;
:: b.foo<float, long>(1.0f);
:: }
::
:: It seems to me that gcc is right, because according standard the
:: Implement
:: method is a dependent name and therefore has to be accessed using
:: this-> , hasn't it?

Yes, and VS8 and VS9 will do that as well, if you ask it to (option
/Za).


Bo Persson
 
M

mojmir

Yes, and VS8 and VS9 will do that as well, if you ask it to (option
/Za).

oh, it's not a bug, it's a feature.. "whadda mistake-a to make-a" :)
thanks for pointing that out, i am quite new to visual studio.

mojmir
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top