#include<iostream>
using namespace std;
class Box
{
private:
int heigh;
int weigh;
int length;
public:
Box();//這是無引數形式的建構式
Box(int h, int w, int len) :heigh(h), weigh(w), length(len){}//這是帶有引數形式的建構式并且
//這是使用引數串列進行初始化的
int volume();
//這是對成員函式的宣告
};
Box::Box()//這是定義一個建構式
{
heigh = 10;
weigh = 11;
length = 12;
}
//int Box::volume()
int Box ::volume( )
{
return (height*width*length);
}
int main()
{
Box box;//這是定義物件
cout << "the volume is" << box.volume() << endl;
Box box1(15, 30, 13);
cout << "THE VOULMEIS" << box1.volume() << endl;
return 0;
}
錯誤提示:
uj5u.com熱心網友回復:
有全角的標點符號uj5u.com熱心網友回復:
我把那個volume函式在類里面定義就可以了,如果不在那里面定義就會說“非靜態存盤資料要在類里面定義”轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/72752.html
標籤:基礎類
