类中定义了bool函数 在main函数中使用时却出现未定义标识符



class cube
{
private:
    int m_L;
    int m_H;
    int m_W;
public:
    void setHeight(int h)  
    {
       
       m_H = h;
    }
    int getHeight()
    {
        return m_H;
    }

   void setLength(int l)  
    {
       
       m_L = l;
    }

    int getLength()
    {
        return m_L;
    }

    void setWidth(int w)  
    {
       
       m_W = w;
    }

    int getWidth()
    {
        return m_W;
    }


    int getArea()
    {
        return   m_H*m_L*2 + m_H*m_W*2 + m_W*m_L*2 ;
        //  cout<< Area << endl;
        
    }
    int getVolume()
    {
        return  m_H*m_L*m_W;
        
    }
    bool isSame (cube &p1, cube &p2)
    {
        if(p1.getHeight() == p2.getHeight() && p1.getLength() == p2.getLength() && p1.getWidth() == p2.getWidth())
        {
            return true;
        }
        return false;
    }


};


#include<iostream>
using namespace std;
int main()
{
    cube p1;
    p1.setHeight(10);
    p1.setLength(10);
    p1.setWidth(10);
    cout<< p1.getArea() << endl;
    cout<< p1.getVolume()<< endl;
    
    cube p2;
    p2.setHeight(1);
    p2.setLength(1);
    p2.setWidth(1);
    cout<< p2.getArea() << endl;
    cout<< p2.getVolume()<< endl;
    

   
    
    bool ret = isSame(p1,p2); _ // 在isSame处下划线  未定义标识符_
    if(ret)
    {
        cout << "p1 = p2" << endl;

    }
    else 
    {
        cout << "p1 != p2" << endl;
    }


    system("pause");
    return 0;
}

你这行直接调用的类中方法,应该是p2.isSame才对,改成这样就行了:

img

bool ret = p2.isSame(p1,p2);

img

isSample是类的成员,需要再实例后面使用,比如p1.isSample(p1,p2)