I’m trying to make use of typedef structs inside of my C++ program. I started writing the following code until I received an error when trying to add a method to my class that returns a template typedef struct pointer.
StructSource.h
template <typename T>
class StructSource {
public:
struct TestStruct{
T value;
};
};
User.h
#include "StructSource.h"
class User {
public:
typedef StructSource<int>::TestStruct IntStruct;
IntStruct *getIntStruct();
};
User.cpp
#include "User.h"
IntStruct *User::getIntStruct() {
return 0;
}
This gives the following error when compiling with GCC.
User.cpp:3:1: error: ‘IntStruct’ does not name a type
I’m at a loss to explain why this is the case. What type information am I missing?
“User” is also a “namespace” (scope, actually, as most commenters point out – “namespace” was for a quick answer) here, so you have to use