问题挺简单的就想知道编译为什么不能执行,#ifndef第一次上机用
程序代码:
#ifndef STOCK10_H_ #define STOCK10_H_ #include<string> class stock { private: std:string company; long shares; double share_val; double total_val; void set tot() {total_val=shares*share val;} public: stock(); stock(const std::string &co,long=0,double pr=0.0); ~stock(); void show(); }; #endif // STOCK10_H_ #include<iostream> #include"stock10.h" stock:stock() { std::cout<<"Default constructor called\n"; company="no name"; shares=0; share_val=0.0; toatal_val=0.0; } stock::stock(const std::string &co,long,double pr) { std::cout<<"Constructor using "<<co<<" called\n"; company=co; shares=n; share_val=pr; set_tot; } stock::~stock() { std::cout<<"Bye, "<<company<<"!\n"; } void stock::show() { using std::cout; using std::endl; cout<<"Company: "<<company <<" shares: "<<shares<<endl <<" share price: "<<share_val <<" total worth: "<<total_val<<endl; } #include<iostream> #include"stock10.h" int main() { { using std::cout; cout<<"Using constructors "<<endl; stock stock1("huang",12,20.0); stock1.show(); } return 0; }
感谢大佬,帮帮忙啊