- 论坛徽章:
- 0
|
/*Teacher.h*/
class Teacher
{
protected:
char *pname;
public:
Teacher(char *name);
Teacher();
void show();
};
/* Teacher.cpp*/
#include "string"
#include "Teacher.h"
#include <iostream>
using namespace std;
Teacher(char* name)
{
pname=new char[10];
strcpy(name,pname);
}
Teacher()
{
}
void Teacher::show()
{
cout<<pname<<endl;
}
/*t-main.cpp*/
#include "Teacher.h"
#include "iostream"
using namespace std;
main()
{
Teacher test1;
Teacher test2("Michael");
test2.show();
}
makefile文件如下:
[fw@localhost c++]$ cat Makefile
t-main:t-main.o Teacher.o
g++ -o t-main t-main.o Teacher.o
t-main.o:t-main.cpp Teacher.h
g++ -c t-main.cpp
Teacher.o:Teacher.cpp Teacher.h
g++ -c Teacher.cpp
运行make, 错误如下:
[fw@localhost c++]$ make
g++ -c Teacher.cpp
Teacher.cpp:5: parse error before `char'
Teacher.cpp:8: `name' was not declared in this scope
Teacher.cpp:8: `pname' was not declared in this scope
Teacher.cpp:8: ISO C++ forbids declaration of `strcpy' with no type
Teacher.cpp:8: `int strcpy' redeclared as different kind of symbol
/usr/include/string.h:83: previous declaration of `char* strcpy(char*, const
char*)'
Teacher.cpp:8: initializer list being treated as compound expression
Teacher.cpp:9: parse error before `}' token
make: *** [Teacher.o] Error 1
高手们,能不能帮我解析一下, |
|