当前位置:编程学习 > C/C++ >>

C++参数传递问题

请问这个错误出在哪里,谢谢了

#include<iostream>
using namespace std;
class father
{
public:
 father(){cout<<"基类构造函数"<<endl;}
 ~father(){cout<<"基类夕照函数"<<endl;}
 void printf(){cout<<name<<"身高为:"<<tall<<endl;}
protected:
 string name;
 int tall;
};
class son:public father
{
public:
 son(string s,int t,int w){name=s;tall=t;weight=w;"cout<<"子类构造函数"<<endl;}
 ~son(){cout<<"子类夕照函数"<<endl;}
 void printf1(){printf();cout<<"体重"<<weight<<endl;}
private:
 int weight;
};
int main()
{
 son sn("mike",180,80);
  sn.printf1();
  return 0;
}

 

答案:#include<iostream>
using namespace std;
class father
{
public:
 father(){cout<<"基类构造函数"<<endl;}
 ~father(){cout<<"基类夕照函数"<<endl;}
 void printf(){cout<<name<<"身高为:"<<tall<<endl;}
protected:
 string name;
 int tall;
};
class son:public father
{
public:
 son(string s,int t,int w){name=s;tall=t;weight=w;"cout<<"子类构造函数"<<endl;}
 ~son(){cout<<"子类夕照函数"<<endl;}
 void printf1(){printf();cout<<"体重"<<weight<<endl;}
private:
 int weight;
};
int main()
{
 son sn("mike",180,80);
  sn.printf1();
  return 0;
}去掉加粗处的引号。就不会有语法错误了。son(string s,int t,int w){name=s;tall=t;weight=w;"(多了个双引号)cout<<"子类构造函数"<<endl;}

son(string s,int t,int w){name=s;tall=t;weight=w;"cout<<"子类构造函数"<<endl;}
多了个引号

son(string s,int t,int w){name=s;tall=t;weight=w;cout<<"子类构造函数"<<endl;}

上一个:C++编程题
下一个:C++程序设计问题

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,