我知道,只要有可能,我们将使用前向声明而不是包含来加快编译速度。
我有这样的课Person
。
#pragma once
#include <string>
class Person
{
public:
Person(std::string name, int age);
std::string GetName(void) const;
int GetAge(void) const;
private:
std::string _name;
int _age;
};
Student
和这样的课
#pragma once
#include <string>
class Person;
class Student
{
public:
Student(std::string name, int age, int level = 0);
Student(const Person& person);
std::string GetName(void) const;
int GetAge(void) const;
int GetLevel(void) const;
private:
std::string _name;
int _age;
int _level;
};
在 Student.h 中,我有一个前向声明class Person;
可以Person
在我的转换构造函数中使用。美好的。但是我已经#include <string>
避免std::string
在代码中使用时出现编译错误。这里如何使用前向声明来避免编译错误?可能吗?
谢谢。