Original Post
This hurts my head. The following works like a charm: However, if I move the whole ESS part in between the specialisations, it does not work: And if I have it anywhere above the specialisation of B, then it compiles again (not going to show this one :D). For the middle case, where it doesn't work, the error is:
#include <iostream>
template <typename T> struct A;
template <typename T> struct B;
typedef A<int> AA;
typedef B<int> BB;
template <> struct B<int>
{
void eat()
{
AA::do_nothing();
std::cout << "EATING" << std::endl;
}
};
template <> struct A<int>
{
void do_thing()
{
BB b;
b.eat();
}
static void do_nothing()
{
}
};
struct ESS
{
ESS()
{
}
void d()
{
int a = 1, b = 2, c = a + b;
}
};
int main()
{
// just to make sure it's not optimised away
ESS es;
es.d();
// do a thing
AA a;
a.do_thing();
}
#include <iostream>
template <typename T> struct A;
template <typename T> struct B;
typedef A<int> AA;
typedef B<int> BB;
template <> struct B<int>
{
void eat()
{
AA::do_nothing();
std::cout << "EATING" << std::endl;
}
};
// ESS is now in between
struct ESS
{
ESS()
{
}
void d()
{
int a = 1, b = 2, c = a + b;
}
};
template <> struct A<int>
{
void do_thing()
{
BB b;
b.eat();
}
static void do_nothing()
{
}
};
int main()
{
// just to make sure it's not optimised away
ESS es;
es.d();
// do a thing
AA a;
a.do_thing();
}
main.cpp(19) : error C2027: use of undefined type 'A<T>'
with
[
T=int
]
main.cpp(19) : error C3861: 'do_nothing': identifier not found It is really doing my head in - does anyone know why that could be? I'm on MSVC2k5 if that helps.