Loading

c++ 的 坑真多之头文件

我发现类在做参数时,是可以不引用头文件,即不用#include"xxx.h"的,比如下面这样是没有问题的

#pragma once
#include <string>
#include <iostream>

class Humankind;
class Person {
public:
    Person();
    void sayHello(Humankind human);
};

但如果这个类是用来被继承,就编译不过,必须写头文件包含,即这样:

#pragma once
#include <string>
#include <iostream>
#include "Humankind.h"
class Person : Humankind{
public:
    Person();
    void sayHello();
};

 

posted @ 2016-05-15 14:41  注销111  阅读(234)  评论(0编辑  收藏  举报