4

我有一个模板类“类型是不完整的”(但不是)和代码编译

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 

哪个是对的。

+1

请提供[mcve]。 – Barry

+0

我不知道这是否对你有帮助,但是你的代码在'g ++'和'clang ++'上工作正常 – tforgione

+0

它也适用于msvc。我认为这是IntelliSense解析器的问题。 – Timo

回答

2

我终于明白这是Resharper的intellisense问题。如果我禁用Resharper,则代码不再加下划线。我会将此报告给JetBrains并让您保持最新状态。

编辑

所有罪恶的根源是函数型的代入函数签名:

template<typename FT = void()> 
struct Func; 

template<typename FR, typename ...FArgs> 
struct Func<FR(FArgs...)> 
{ 
    // ... 
} 

更新

我开一张票上youtrack(JetBrain的问题跟踪器),并且开发人员已分配给它。