小编tre*_*oon的帖子

C++ #include循环

文件Dog.h

#ifndef DOG_H
#define DOG_H

#include "Cat.h"
//class Cat;

class Dog
{
        Cat c;
};

#endif
Run Code Online (Sandbox Code Playgroud)

文件Cat.h

#ifndef CAT_H
#define CAT_H

#include "Dog.h"
//class Dog;

class Cat
{
        Dog d;
};

#endif
Run Code Online (Sandbox Code Playgroud)

这导致循环,问题是两个类需要彼此了解; 前向声明也没有解决问题.您可以创建Dog d或Cat c的指针来解决它.

问题:是否真的没有办法不创建指针,即保持代码不重写我想要的方式?

c++ loops include

2
推荐指数
1
解决办法
453
查看次数

标签 统计

c++ ×1

include ×1

loops ×1