64,648
社区成员
发帖
与我相关
我的任务
分享
class Car;
class Apple;
class Apple{
Car aCar;
}
};
class Car{
Apple anApple;
};
int main(){
return 0;
}
icl: NOTE: The evaluation period for this product ends on 24-jan-2008 UTC.
examp.cpp
examp.cpp(7): error: pointer to incomplete class type is not allowed
aCar->bcd();
^
compilation aborted for examp.cpp (code 2)
class Car;
class Apple;
class Apple{
public:
void abc(Car *aCar){
aCar->bcd();
}
};
class Car{
public:
Apple anApple;
void bcd(){ }
};
int main(){
Apple app;
Car car;
app.abc(&car);
return 0;
}
class Car;
class Apple;
class Apple{
Car *aCar;
void abc(){
aCar->bcd();
}
}
};
class Car{
Apple anApple;
void bcd(){ }
};
int main(){
return 0;
}
//指针的好处就是推迟实现嘛...
#include<iostream>
using namespace std;
class Car;
class Apple;
class Apple
{
public:
void abc(Car *aCar);
};
class Car
{
public:
Apple anApple;
void bcd(){ cout<<"The car is excuted!"<<endl;}
};
void Apple::abc(Car *aCar) //将aCar的调用放到car类的定义之后;
{
aCar->bcd();
}
int main()
{
Apple app;
Car car;
app.abc(&car);
return 0;
}
class Car;
class Apple
{
Car *aCar;
public:
void abc();//须定义在外面
};
class Car
{
Apple anApple;
public:
void bcd()
{
cout<<"Car::bcd()\n";
}
};
void Apple::abc()
{
cout<<"Apple::abc()\n";
aCar->bcd();
}
int main()
{
Apple a;
a.abc();
////////////////////////////////////////////////////////
system("PAUSE");
return 0;
}
你的程序就是典型的”你中有我,我中有你“
1楼正解啊;肯定要用指针的, 只有这样才能推迟对象的定义的啊;
class Car;
class Apple;
class Apple{
Car* aCar;
};
class Car{
Apple* anApple;
};
int main(){
return 0;
}