关于构造函数的问题
#include<iostream.h>#include<stdlib.h>
class Stock
{
char stockcode[10];
int quan;
double price;
public:
Stock(char cd[],int q=1000 ,double p=8.98)
{
strcpy(stockcode,cd);
quan=q;
price=p;
}
void print(void);
};
void Stock::print(void)
{
cout<<this->stockcode<<" ";
cout<<this->quan<<" ";
cout<<this->price<<endl;
}
int main()
{
Stock A="a",B("a",500,9.0);
A.print();
B.print();
system("pause");
}
这个程序在声明构造函数时必须给出定义吗?
为什么在类外定义构造函数时会出错?