诚心求教解决思路

诚心求教程序如下:#include iostream#include stringusingnamespacestdclassTeacher{public:Teacher(

诚心求教
程序如下:
#include <iostream>
#include <string>
using   namespace   std;
class   Teacher
{
public:
Teacher(string   nam,int   a,string   t)
{name=nam;
  age=a;
  title=t;
}
  void   display()
  {
    cout < < "name: " < <name < <endl;
    cout < < "age: " < <age < <endl;
    cout < < "title: " < <title < <endl;
  }
protected:
string   name;
int   age;
string   title;
};


class   Student
{public:
          Student(char   nam[],char   s,float   sco)
  {
          strcpy(name1,nam);
  sex=s;
  score=sco;
  }
  void   display1()
  {   cout < < "name: " < <name1 < <endl;
      cout < < "sex: " < <sex < <endl;
      cout < < "score: " < <score < <endl;
  }
protected:
string   name1;
char   sex;
float     score;
};


class   Graduate:public   Teacher,public   Student
{
public:
Graduate(string   nam,int   a,char   s,string   t,float   sco,float   w):
    Teacher(nam,a,t),Student(nam,s,sco),wage(w){}
      void   show()
      {cout < < "name: " < <name < <endl;
      cout < < "age: " < <age < <endl;
      cout < < "sex: " < <sex < <endl;
      cout < < "score: " < <score < <endl;
      cout < < "title: " < <title < <endl;
      cout < < "wages: " < <wage < <endl;
      }
private:
    float   wage;
};
int   main()
{
Graduate   grad1( "wangli ",25, 'f ', "asssdfdf ",96.1,2546.3);
  grad1.show();
  return   0;
}


用visual   c++编译提示:
error   C2664:   'strcpy '   :   cannot   convert   parameter   1   from   'class   std::basic_string <char,struct   std::char_traits <char> ,class   std::allocator <char>   > '   to   'char   * '
                No   user-defined-conversion   operator   available   that   can   perform   this   conversion,   or   the   operator   cannot   be   called


不知道是什么意思。。。。

[解决办法]
strcpy(name1,nam);
改为:
name1 = nam;
[解决办法]
Student 类中 strcpy(name1,nam); 改成 name1 = nam;

更推荐的做法是把这个放在成员初始化列表里初始化.
[解决办法]
意思就是你调用strcpy的参数不对
strcpy的原型为char *strcpy(char *str1, const char *str2);
你的name1是一个string无法转换成char *,你可以使用name1=string(nam);实现你想要的功能
------解决方案--------------------


建议你编程时随手有一本标准库的参考比如C&C++.Programmers.Reference
到网上可以搜索到电子版
[解决办法]
在student类中,先把char nam[]改为string nam,strcpy(name1,nam)改为name1=nam
构造函数是用来初始化的,即付值,strcpy(name1,nam)虽然能起到相同的作用,但意义不同