问题描述:
#include<stdio.h>
#include<conio.h>
#include<string.h>
class RELATIONSHIP
{
private:RELATIONSHIP*BABY;
char*NAME;
public:RELATIONSHIP(char*Name);
void CreateBaby(char*BABY_NAME);
void Display_People();
void Display_Baby();
}
RELATIONSHIP::RELATIONSHIP(char*Name)
{
NAME=new char[strlen(Name)+1];
strcpy(NAME,Name);
}
void RELATIONSHIP::CreateBaby(char*BabyName)
{
BABY=new RELATIONSHIP(BabyName);
}
void RELATIONSHIP::Display_People()
{
printf("THE FIRST PEOPLE:%s",this->NAME);
}
void RELATIONSHIP::Display_Baby()
{
printf("HER BABY:%s",this->BABY->NAME);
}
int main(void)
{
RELATIONSHIP People("L1");
People.CreateBaby("L2");
People.Display_People();
People.Display_Baby();
getch();
return 0;
}
Compiling...
类的自引用.cpp
C:\Documents and Settings\Administrator\类的自引用.cpp(15) : error C2533: 'RELATIONSHIP::RELATIONSHIP' : constructors not allowed a return type
C:\Documents and Settings\Administrator\类的自引用.cpp(22) : error C2264: 'RELATIONSHIP::RELATIONSHIP' : error in function definition or declaration; function not called
C:\Documents and Settings\Administrator\类的自引用.cpp(35) : error C2264: 'RELATIONSHIP::RELATIONSHIP' : error in function
错在哪里?怎么改
问题解答:
基本没错误,只是类定义之后没加分号。