1

I keep getting weird C4430 and C2143 errors when I try to compile my code. My class has data members which point to different classes and the errors are saying that it is expecting a ";" in between the class name and "*". Here's a summary of my class:

#include "CarStack.h"
#include "CarQueue.h"    
#include "CarDeque.h"
#include "base_class.h"

class my_class : public base_class
{
public:
    //Member Functions
private:
    //Other data members
    CarStack* car_stack;
    CarQueue* car_queue;
    CarDeque* car_deque;
};

The errors are coming up with those class pointers. Why would I get errors like this? Is there something important I'm missing?

4

1 回答 1

0

如果基类或任何汽车类调用此列表中的其中之一,您将获得循环依赖。有很多解决方案。

我发现最好的解决方案:从我最近的 opengl 项目“Include.h”中复制粘贴包含:

#ifndef _INCLUDE_H
#define _INCLUDE_H

#include <Windows.h>
#include "SDL.h"
#include "gl/gl.h"
#incldue "gl/glu.h"

#include "Most Derived Classes"
#include "Most Derived Classes"

#endif

然后,只需#include "Include.h"在项目的主驱动程序文件的开头使用。然后,仅包含派生类的基本标头。

我认为这是一个更好的解决方案,一堆前向声明,IMO。

于 2013-06-26T04:16:47.250 回答