假设您有一些目标类,其中包含一些方法:
class Subject
{
public:
void voidReturn() { std::cout<<__FUNCTION__<<std::endl; }
int intReturn() { std::cout<<__FUNCTION__<<std::endl; return 137; }
};
Run Code Online (Sandbox Code Playgroud)
和Value类(概念类似于Boost.Any):
struct Value
{
Value() {}
Value( Value const & orig ) {}
template< typename T > Value( T const & val ) {}
};
Run Code Online (Sandbox Code Playgroud)
我想使用Subject类中的方法生成一个Value对象:
Subject subject;
Value intval( subject.intReturn() );
Value voidVal( subject.voidReturn() ); // compilation error
Run Code Online (Sandbox Code Playgroud)
我在VC++ 2008中遇到以下错误:
error C2664: 'Value::Value(const Value &)' : cannot convert parameter 1 from 'void' to 'const Value &'
Expressions of type void cannot …Run Code Online (Sandbox Code Playgroud)