c++ 使用类与对象计算体积的简单问题

图片说明

    /*初学类与对象,为了方便,我把全部程序写在了同一个cpp文件里,但错误提示 'set' : overloaded member function 'void (unsigned int,unsigned int,unsigned int)' not found in 'CBox',大神们帮我看看是不是set函数的问题,该怎么改?*/

#include "stdafx.h"
#include<iostream>
using namespace std;

class CBox{
private:
    unsigned int m_nLength;
    unsigned int m_nWidth;
    unsigned int m_nHeight;
public:
    void set();
    void print();
    int getVolume(unsigned int Length,unsigned int Width,unsigned int Height);
};
void CBox:: print ()
{
    cout<<m_nLength;
    cout<<m_nWidth;
    cout<<m_nHeight;
}
void CBox:: set(unsigned int Length,unsigned int Width,unsigned int Height)
{
    cin>>Length;
    cin>>Width;
    cin>>Height;

    m_nLength=Length;
    m_nWidth=Width;
    m_nHeight=Height;
}
int CBox:: getVolume(unsigned int Length,unsigned int Width,unsigned int Height)
{
    Length=m_nLength;
    Width=m_nWidth;
    Height=m_nHeight;

    return (Length*Width*Height);
}

int main(int argc, char* argv[])
{
    CBox r1,r2;
    r1.set();
    r1.print();
    cout<<r1.getVolume<<endl;

    r2.set();
    r2.print();
    cout<<r2.getVolume;
    return 0;
}

感觉你的set和getVolume都不需要传入参数

#include "stdafx.h"
 #include<iostream>
using namespace std;

class CBox{
private:
    unsigned int m_nLength;
    unsigned int m_nWidth;
    unsigned int m_nHeight;
public:
    void set();
    void print();
    int getVolume();
};
void CBox:: print ()
{
    cout<<m_nLength;
    cout<<m_nWidth;
    cout<<m_nHeight;
}
void CBox:: set()
{
    unsigned int Length,Width,Height;
    cin>>Length;
    cin>>Width;
    cin>>Height;

    m_nLength=Length;
    m_nWidth=Width;
    m_nHeight=Height;
}
int CBox:: getVolume()
{
    int Length=m_nLength;
    int Width=m_nWidth;
    int Height=m_nHeight;

    return (Length*Width*Height);
}

int main(int argc, char* argv[])
{
    CBox r1,r2;
    r1.set();
    r1.print();
    cout<<r1.getVolume()<<endl;

    r2.set();
    r2.print();
    cout<<r2.getVolume();
    return 0;
}

图片说明

你的set声明是无参数,但定义的时候又有了,所以错了