Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 超载不';t为<&书信电报;_C++_Linked List_Operator Overloading - Fatal编程技术网

C++ 超载不';t为<&书信电报;

C++ 超载不';t为<&书信电报;,c++,linked-list,operator-overloading,C++,Linked List,Operator Overloading,我有这段代码,我无法计算头重载->信息==0) 你用了一种错误的方式。。。类内的重载运算符允许您将该类用作运算符的左操作数。。。所以基本上你可以做B你是以错误的方式做的。。。类内的重载运算符允许您将该类用作运算符的左操作数。。。所以基本上你可以做B更喜欢一个全局操作符更喜欢一个全局操作符操作符operatoroperatoroperator>apparently'Boperator>apparently'B好的,所以,我把这个函数从类中去掉了,把它变成了朋友。唯一的问题是我有未声明的变量(nod

我有这段代码,我无法计算头重载->信息==0)
你用了一种错误的方式。。。类内的重载运算符允许您将该类用作运算符的左操作数。。。所以基本上你可以做
B你是以错误的方式做的。。。类内的重载运算符允许您将该类用作运算符的左操作数。。。所以基本上你可以做
B更喜欢一个全局
操作符更喜欢一个全局
操作符
操作符
operator
operator
operator>apparently'B
operator>apparently'B好的,所以,我把这个函数从类中去掉了,把它变成了朋友。唯一的问题是我有未声明的变量(node/temp未在此作用域中声明,而类MY_class没有名为info的成员。我假设这是因为我没有将函数放在您前面提到的命名空间中。问题是…我不知道这是什么,也不知道需要注意什么。首先,重载运算符需要与您的类型位于同一命名空间中。您可以因此,需要在源代码中包含所有正在使用的头文件和命名空间:
usingnamespace your_namespace;
用于代码中使用的所有命名空间。好的,所以,我将函数从类中取出,并将其作为朋友。唯一的问题是我有未声明的变量(node/temp未在此作用域中声明,而类MY_class没有名为info的成员。我假设这是因为我没有将函数放在您前面提到的命名空间中。问题是…我不知道这是什么,也不知道需要注意什么。首先,重载运算符需要与您的类型位于同一命名空间中。您可以因此,需要在源代码中包含您正在使用的所有头文件和命名空间:
使用命名空间您的_namespace;
用于代码中使用的所有命名空间。
 ostream& operator<<(ostream& out)
     {int check=0;  
    node *temp;     
    temp=this->head->next;
    if(this->head->info==0)
        out<<"- ";  
    while(temp!=NULL)
        {   if(temp->info)
            {out<<temp->info<<" ";
            check=1;
        temp=temp->next;}
            else    if(temp->info==0&&check==1)
            {out<<temp->info<<" ";
                temp=temp->next;}
            else temp=temp->next;
        }
        return out;

    }
 cout<< B;
ostream& operator<<(ostream& out, TYPE_OF_YOUR_CLASS_HERE v)
{
    int check=0;  
    node *temp;     
    temp=b.head->next;
    if(v.head->info==0)
        out<<"- ";  
    while(temp!=NULL)
    {   
        if(v.info) {
            out<<v.info<<" ";
            check=1;
            temp=temp->next;
        } else if(temp->info==0&&check==1) {
            out<<temp->info<<" ";
            temp=temp->next;
        }
        else 
            temp=temp->next;
    }
    return out;
}
class MY_CLASS {
    ...
    friend ostream& operator<< (ostream& out, MY_CLASS v);
};
ostream& output(ostream& out) const
{
    // Your code here.
}
ostream& operator<<(ostream& os, const MyClass& c) 
{ 
    return c.output(os); 
}