-5
假设我们有两个类Foo和Bar。 我们可以声明Foo类和使用它的方法如下:正向声明一个类并声明一个类的变量有什么区别?
#include"foo.h"
Foo foo
class Bar{
Bar(){
foo.method1();
}
}
而且我们有向前声明,主张声明Foo类如下:
#include"foo.h"
class Foo
class Bar{
Bar(){
}
}
主要有哪些区别在两个声明之间,以及何时正向声明更喜欢前向声明?
有用的链接:https://www.quora.com/What-exactly-is-the-difference-between-the-declaration-of-a-class-and-a-definition-of-a-class –
在你的第二个例子中'Foo'永远不会被使用,所以我不明白你的问题 – bolov
[C++ - Forward declaration](http://stackoverflow.com/questions/4757565/c-forward-declaration) – dkg