错误:变量或字段'function'声明为void [英] error: variable or field 'function' declared void

查看:217
本文介绍了错误:变量或字段'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.


推荐答案

On 5/12/2018 8:01 AM,forever a loser写道:

On 5/12/2018 8:01 AM, forever a loser wrote:


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){}

有关说明,请参阅
https://stackoverflow.com/questions/610245/where-and-why-do- i-have-to-put-the-template-and-typename-keywords


这篇关于错误:变量或字段'function'声明为void的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆