我的类是这样写的
class base
{
private:
int id;
char *name;
int getId()
{
return id;
}
*char getName()
{
return *name;
}
void setId(int id)
{
this->id=id;
}
void setName(char *name)
{
this->name=name;
}
}
主函数里这样调用的
int main(int argc, char* argv[])
{
base b;
char *p="xxxxx";
b.setName(p);
cout<<b.getName();
return 0;
}
报了一车错误:
e:\wokc++\继承多态\test\base.h(15) : warning C4518: 'char ' : storage-class or type specifier(s) unexpected here; ignored
e:\wokc++\继承多态\test\base.h(16) : error C2501: 'getName' : missing storage-class or type specifiers
e:\wokc++\继承多态\test\base.h(18) : warning C4183: 'getName': member function definition looks like a ctor, but name does not match enclosing class
E:\wokc++\继承多态\test\test.cpp(11) : error C2628: 'base' followed by 'int' is illegal (did you forget a ';'?)
E:\wokc++\继承多态\test\test.cpp(15) : error C2248: 'setName' : cannot access private member declared in class 'base'
e:\wokc++\继承多态\test\base.h(25) : see declaration of 'setName'
E:\wokc++\继承多态\test\test.cpp(17) : error C2065: 'cout' : undeclared identifier
E:\wokc++\继承多态\test\test.cpp(17) : error C2248: 'getName' : cannot access private member declared in class 'base'
e:\wokc++\继承多态\test\base.h(15) : see declaration of 'getName'
E:\wokc++\继承多态\test\test.cpp(17) : error C2297: '<<' : illegal, right operand has type 'int *'
E:\wokc++\继承多态\test\test.cpp(19) : error C2664: '__thiscall base::base(const class base &)' : cannot convert parameter 1 from 'const int' to 'const class base &'
Reason: cannot convert from 'const int' to 'const class base'
No constructor could take the source type, or constructor overload resolution was ambiguous
E:\wokc++\继承多态\test\test.cpp(19) : error C2553: no legal conversion of return value to return type 'class base *'
E:\wokc++\继承多态\test\test.cpp(20) : warning C4508: 'main' : function should return a value; 'void' return type assumed
各位大师...我知道 ..我
*char getName()
{
return *name;
}
错了..麻烦指点下应该怎么写
函数式编程
拉莫斯之舞
人到中年有点甜