문제

I have a class, which have a public templated methods. This class has 2 strategies of behavior, which i want to pass via class template.

template<class Strategy>
class SomeClass {
public:
    template<class B>
    void ProcessType(){}
};

// And do something like this:
SomeClass<Strategy1> sc();
sc.ProcessType<SomeClassType>();
sc.ProcessType<SomeClassType2>();

SomeClass<Strategy2> sc2();
sc2.ProcessType<SomeClassType>();
sc2.ProcessType<SomeClassType2>();

But this code doesn't compile. I need to keep usage exact like this (to manipulate just via strategy).

도움이 되었습니까?

해결책

This is the problem:

SomeClass<Strategy1> sc();

That is a declaration of a function called sc that takes no arguments and returns a SomeClass<Strategy1>. This is commonly known as a vexing parse (but not the most vexing parse). What you want is:

SomeClass<Strategy1> sc;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top