Mycroft Holmes
2009-10-05 10:02:56 UTC
Hi everyone,
We are having some problem with using declarations of the form "using
BASE_CLASS::type;".
Not sure this is allowed by the standard... most compilers (including
Comeau) accept it, but some give inconsistent results.
The code looks as follows:
template <typename T>
class my_base
{
public:
typedef T type;
};
template <typename T>
class my_object : public my_base<T>
{
public:
using typename my_base<T>::type;
type get_instance() const
{
return type();
}
};
class AAA
{
private:
class BBB
{
public:
int do_something() const { return 7; }
};
public:
int do_all() const
{ return my_object<BBB>().get_instance().do_something(); }
};
int main()
{
AAA myA;
return myA.do_all();
}
1) VC2008 returns error on "return type();"
error C2597: illegal reference to non-static member
'my_object<T>::type'
however if I change the code like this, it works:
type get_instance() const
{
type t; return t;
2) intel compiler 10.1 reports a strange error (something like
my_base<T>::type is not accessible from my_object). Actually, the
problem occurs because BBB is private inside AAA (if I make it public,
then it compiles just fine).
3) Comeau online accepts the code, so it shouldn't be too illegal
Note that the question is purely academic, since I could just re-
typedef "typedef typename BASE_CLASS::type type;" and get the same net
result (and all compilers behave correctly).
-- MH
We are having some problem with using declarations of the form "using
BASE_CLASS::type;".
Not sure this is allowed by the standard... most compilers (including
Comeau) accept it, but some give inconsistent results.
The code looks as follows:
template <typename T>
class my_base
{
public:
typedef T type;
};
template <typename T>
class my_object : public my_base<T>
{
public:
using typename my_base<T>::type;
type get_instance() const
{
return type();
}
};
class AAA
{
private:
class BBB
{
public:
int do_something() const { return 7; }
};
public:
int do_all() const
{ return my_object<BBB>().get_instance().do_something(); }
};
int main()
{
AAA myA;
return myA.do_all();
}
1) VC2008 returns error on "return type();"
error C2597: illegal reference to non-static member
'my_object<T>::type'
however if I change the code like this, it works:
type get_instance() const
{
type t; return t;
2) intel compiler 10.1 reports a strange error (something like
my_base<T>::type is not accessible from my_object). Actually, the
problem occurs because BBB is private inside AAA (if I make it public,
then it compiles just fine).
3) Comeau online accepts the code, so it shouldn't be too illegal
Note that the question is purely academic, since I could just re-
typedef "typedef typename BASE_CLASS::type type;" and get the same net
result (and all compilers behave correctly).
-- MH