我有一個模板類「類型是不完整的」(但不是)和代碼編譯
template<typename EventT, typename StateT, typename ActionT, bool InjectEvent = false, bool InjectStates = false, bool InjectMachine = false>
class StateMachine;
和它的專業化
template<typename EventT, typename StateT, typename ActionResultT, typename ...ActionArgsT, bool InjectEvent, bool InjectStates, bool InjectMachine>
class StateMachine<EventT, StateT, ActionResultT(ActionArgsT...), InjectEvent, InjectStates, InjectMachine>
專業化是用來解決函數類型到它的返回和參數類型。
該類的實現按預期工作,並通過了所有測試。
如果我通過使ActionT = void()
默認值添加到ActionT
,Visual Studio中抱怨「式的StateMachine < ...>是不完整的」智能感知和停止工作(至少對於這種類型的所有實例)。 但是代碼編譯和所有測試都像以前一樣傳遞(我也有一個明確使用默認參數的測試)。
這是Visual Studio中的錯誤還是我錯過了什麼?
我使用VS 2015年Pro和C++ 14
編輯
這裏是一個最小的工作例如:
#include <iostream>
#include <functional>
using namespace std;
template<typename EventT, typename StateT, typename ActionT = void(), bool InjectEvent = false, bool InjectStates = false, bool InjectMachine = false>
class StateMachine;
template<typename EventT, typename StateT, typename ActionResultT, typename ...ActionArgsT, bool InjectEvent, bool InjectStates, bool InjectMachine>
class StateMachine<EventT, StateT, ActionResultT(ActionArgsT...), InjectEvent, InjectStates, InjectMachine>
{
public:
typedef ActionResultT ActionT(ActionArgsT...);
StateMachine(ActionT&& action) : _action(action)
{
}
ActionResultT operator()(ActionArgsT... args)
{
return _action(args...);
}
void sayHello() const
{
cout << "hello" << endl;
}
private:
function<ActionT> _action;
};
int sum(int a, int b)
{
return a + b;
}
void print()
{
cout << "hello world" << endl;
}
void main()
{
StateMachine<string, int, int(int, int)> sm1(sum);
sm1.sayHello();
cout << sm1(2, 5) << endl;
StateMachine<string, int> sm2(print);
sm2();
sm2.sayHello();
getchar();
}
智能感知拋出這個錯誤:
對於SM1它找到的成員函數sayHello()
...
但不能用於SM2
然而代碼編譯併產生以下輸出:
hello
7
hello world
hello
哪個是對的。
請提供[mcve]。 – Barry
我不知道這是否對你有幫助,但是你的代碼在'g ++'和'clang ++'上工作正常 – tforgione
它也適用於msvc。我認爲這是IntelliSense解析器的問題。 – Timo