本文介绍了错误:变量或字段'function'声明为void的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
template<typename Type>
class A
{
public:
Type object;
class B
{
public:
Type object;
B(const Type& obj) : object(obj) {}
B(A& a) : object(a.object) {}
};
A(const Type& obj) : object(obj) {}
};
template<typename Type>
void function(A<Type>::B& b) {}
如果我从上面的代码中删除:: B字符串然后在http://cpp.sh/上的C ++ Shell编译器编译上面的代码没有错误。
那么为什么我用:: B字符串得到这个奇怪的错误在上面的代码中?
$
它将我视为有效的C ++代码。
If I delete the ::B string from the code above then C++ Shell compiler at http://cpp.sh/ compiles the above code with no errors.
Then why I get this weird error with the ::B string in the above code?
It looks for me as a valid C++ code.
推荐答案
template<typename Type>
class A
{
public:
Type object;
class B
{
public:
Type object;
B(const Type& obj) : object(obj) {}
B(A& a) : object(a.object) {}
};
A(const Type& obj) : object(obj) {}
};
template<typename Type>
void function(A<Type>::B& b) {}
设为[code] template< typename Type> void function(typename A< Type> :: B& b){}
这篇关于错误:变量或字段'function'声明为void的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!