注册 登录
编程论坛 C++教室

简单程序 编译不能通过

zzt_428 发布于 2008-12-06 20:01, 468 次点击
下面是一个简单的程序,我调试了很长时间,编译就是不能通过,哪位能指点一下?最好把错的地方标出来,谢谢
//person.h--类定义#ifndef PERSON_H_
#define PERSON_H_


#include <cstring>

class Person
{
public:
    Person()
    {
        lname=" ";
        fname[0]='\0';
    }
    Person(const string & ln,const char *fn = "Heyyou")
    {
        lname=ln;
        fname=fn;
    }
    void Show() const;
    void FormalShow() const;
private:
    enum{LIMIT=25};
    string lname;
    char fname[LIMIT];
};

#endif
//person.cpp--类实现

#include <iostream>
#include "person.h"
using namespace std;


void Person::Show() const
{
    cout << fname << "," << lname << endl;
}

void Person::FormalShow() const
{
    cout << lname << "," << fname << endl;
}
//useperson.cpp--使用类

#include <iostream>
#include "person.h"

int main()
{
    Person one;
    Person two("Smythecraft");
    Person three("Dimwiddy", "Sam");
    one.Show();
    one.FormalShow();

    two.Show();
    two.FormalShow();

    three.Show();
    three.FormalShow();

    return 0;
}
2 回复
#2
newyj2008-12-06 20:41
我 合起来 编译了一下
Person(const string & ln,const char *fn = "Heyyou")
    {
        lname=ln;
        fname=fn;
    }
中的fname=fn; 要改为 strcpy(fname,fn);
#3
zzt_4282008-12-06 23:22
多谢楼上的~~~~~
1