我的简单程序编译不过,请高手指教

xiaoerliao 2007-07-10 10:30:39
我在空工程(蔡泽华)里面建立3个文件,编译出现错误,如下:
主文件40224.cpp:
#include<iostream.h>
#include<string.h>
#include "224.h"
void main()
{
MyClass MC;
MC.MyClass("蔡泽华","071240224");
MC.Print();
}

头文件224.h:
#include<iostream.h>
#include<string.h>
class MyClass
{
private:
char Name[10],No[10];
public:
MyClass()
{
strcpy(Name,"default");
strcpy(No,"999999");
}
MyClass(char *name,char *no);
void Print();
}

实现头文件里面 类的函数224.cpp
#include<iostream.h>
#include<string.h>
#include"224.h"
MyClass::MyClass(char *name,char *no)
{
strcpy(Name,name);
strcpy(No,no);
}
MyClass::Print()
{
cout<<"我的名字是"<<Name<<endl;
cout<<"我的学号是"<<No<<endl;
}


编译出现如下错误:
--------------------Configuration: 蔡泽华 - Win32 Debug--------------------
Compiling...
224.cpp
c:\documents and settings\administrator\桌面\面向对象程序设计\071240224\蔡泽华\224.cpp(4) : error C2143: syntax error : missing ';' before 'PCH creation point'
40224.cpp
c:\documents and settings\administrator\桌面\面向对象程序设计\071240224\蔡泽华\40224.cpp(3) : error C2143: syntax error : missing ';' before 'PCH creation point'
c:\documents and settings\administrator\桌面\面向对象程序设计\071240224\蔡泽华\40224.cpp(6) : error C2274: 'function-style cast' : illegal as right side of '.' operator
执行 cl.exe 时出错.

蔡泽华.exe - 1 error(s), 0 warning(s)

...全文
90 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
i_love_pc 2007-07-10
  • 打赏
  • 举报
回复
MyClass MC;
MC.MyClass("蔡泽华","071240224");//构造函数ms不能这样调用
====================================================================

MyClass *MC=new MyClass();
//或者
//MyClass *MC=new MyClass("蔡泽华","071240224");

MC->Print();
xiaoerliao 2007-07-10
  • 打赏
  • 举报
回复
谢谢,还有提示主文件里面
MC.MyClass("蔡泽华","071240224");
MC后面那个"."的问题
constantine 2007-07-10
  • 打赏
  • 举报
回复
missing ';' ---不是说得很明白吗
cczlp 2007-07-10
  • 打赏
  • 举报
回复
class MyClass
{
...
}; //最后加分号
Jim@luckeeinc.com 2007-07-10
  • 打赏
  • 举报
回复
没仔细看程序
把你的程序放在一个英文目录下面先
路径中不要出现汉字
xiaoerliao 2007-07-10
  • 打赏
  • 举报
回复
注:我在"实现头文件里面 类的函数224.cpp "
里面的Print函数已经修改为:
void MyClass::Print()
{

}

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧