I am trying to change a private variable of a class inside an object, which is initialized inside that class. My intention can be drawn from the simple example below. the Increment
called from obj should increase the BaseClass::stuff
.
template <typename ObjectType>
class BaseClass{
private:
typedef int SampleType; // give custom name type
int stuff = 0;
ObjectType obj;
public:
int Increment(){
return obj.Increment<SampleType>(stuff);
}
};
class ObjectType{
public:
template <typename T>
int Increment (T& stuff)
{
return stuff++;
};
};
int main () {
BaseClass<ObjectType> base;
base.Increment(); // should increase stuff by 1;
}
The problem is that when I try to access ObjectType::Increment
via obj.Increment<int>(stuff);
, it gives me an error below:
error: expected primary-expression before ‘>’ token
return obj.Increment<SampleType>(stuff);
I am having a hard time seeing the cause of this problem.