"Type is incomplete"(但不是)并且代码编译
"Type is incomplete" (but isn't) and code compiles
我有模板class
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>
特化用于将函数类型解析为其 return- 和参数类型。
class 的实现按预期工作并且通过了所有测试。
如果我将默认值添加到 ActionT
使其成为 ActionT = void()
,Visual Studio 会抱怨 "type StateMachine<...> is incomplete" 并且 IntelliSense 停止工作(至少对于此的所有实例类型)。
然而,代码编译并且所有测试都像以前一样通过(我还有一个显式使用默认参数的测试)。
这是 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();
}
IntelliSense 抛出此错误:
对于 sm1 它找到成员函数 sayHello()
...
但不适用于 sm2
但是代码编译并产生了这个输出:
hello
7
hello world
hello
这是正确的。
终于想通了,原来是Resharper的intellisense的问题。如果我禁用 Resharper,代码将不再带有下划线。我会将此报告给 JetBrains 并让您了解最新信息。
编辑
万恶之源在于将函数类型代入函数签名:
template<typename FT = void()>
struct Func;
template<typename FR, typename ...FArgs>
struct Func<FR(FArgs...)>
{
// ...
}
更新
我在 youtrack(JetBrain 的问题跟踪器)上开了一张票,并且已经为它分配了一名开发人员。
我有模板class
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>
特化用于将函数类型解析为其 return- 和参数类型。
class 的实现按预期工作并且通过了所有测试。
如果我将默认值添加到 ActionT
使其成为 ActionT = void()
,Visual Studio 会抱怨 "type StateMachine<...> is incomplete" 并且 IntelliSense 停止工作(至少对于此的所有实例类型)。
然而,代码编译并且所有测试都像以前一样通过(我还有一个显式使用默认参数的测试)。
这是 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();
}
IntelliSense 抛出此错误:
对于 sm1 它找到成员函数 sayHello()
...
但不适用于 sm2
但是代码编译并产生了这个输出:
hello
7
hello world
hello
这是正确的。
终于想通了,原来是Resharper的intellisense的问题。如果我禁用 Resharper,代码将不再带有下划线。我会将此报告给 JetBrains 并让您了解最新信息。
编辑
万恶之源在于将函数类型代入函数签名:
template<typename FT = void()>
struct Func;
template<typename FR, typename ...FArgs>
struct Func<FR(FArgs...)>
{
// ...
}
更新
我在 youtrack(JetBrain 的问题跟踪器)上开了一张票,并且已经为它分配了一名开发人员。