This code doesn’t compile (gives errors C2059, C2065, C2072, C2143, C2146, C2447, C2470, C4430)
But does if you change B* to an inbuild type like int.
Any ideas?
template <typename T>
class A
{
private:
struct B
{
T key;
};
B* foobar(T key);
};
template <typename T>
B* A<T>::foobar(T key)
{
B* ptr = new B;
B->key = key;
return ptr;
}
int main()
{}
You have a few errors in your method.
1) the return type’s scope must be properly qualified.
2) You have to set the
keyif aA::<T>::Binstance, not aB.Try this: