简体   繁体   English

一个包含3个对象的类,这些对象具有彼此的指针,以及一个初始化列表以将引用传递给这些对象。 错误

[英]A class containing 3 objects, which have pointers to each other, and an initialisation list to pass references to those objects. ERROR

Agent.h : //#include "Genetics.h" "Sensors.h" "Effectors.h" Agent.h ://#include“ Genetics.h”“ Sensors.h”“ Effectors.h”

class C_Agent
{
public:

    C_Agent();

    C_Genome Genome;
    C_Sensors Sensors;
    C_Effectors Effectors;
    s_agentParameters parameters; 
}; 

Agent.cpp : //#include "Agent.h" Agent.cpp ://#include“ Agent.h”

C_Agent::C_Agent() 
: parameters(), Sensors(& parameters), Effectors(& parameters),
  Genome(& Sensors, & Effectors)
{ 
    //setup parameters
    Effectors.p_Genome = & Genome; 
}

Sensors.h : //#include "Genetics.h" Sensors.h ://#include“ Genetics.h”

class C_Sensors
{
  public:
    s_agentParameters * p_parameters;
    C_sensors(s_agentParameters * p_parametersRef);
};

Sensors.cpp : //#include "Sensors.h" Sensors.cpp ://#include“ Sensors.h”

C_Sensors::C_Sensors(s_agentParameters * p_parametersRef)
: p_parameters(p_parametersRef) {}

Effectors.h //#include "Genetics.h" Effectors.h //#include“ Genetics.h”

class C_Effectors
{
public:
    s_agentParameters * p_parameters;
    C_Genome * p_Genome;                               //forbids declaration w/ no type
    C_Effectors(s_agentParameters * p_parametersRef);
};

Effectors.cpp : //#include "Effectors.h" Effectors.cpp ://#include“ Effectors.h”

C_Effectors::C_Effectors(s_agentParameters * p_parametersRef)
: p_parameters(p_parametersRef) {}

Genetics.h : //#include "Sensors.h" "Effectors.h" Genetics.h ://#include“ Sensors.h”“ Effectors.h”

class C_Genome
{
public:
    C_Sensors * p_Sensors;                             //forbids declaration w/ no type
    C_Effectors * p_Effectors;                         //forbids declaration w/ no type
    C_Genome(C_Sensors * p_C_SensorsRef, C_Effectors * p_C_EffectorsRef);
};

Genetics.cpp : //#include "Genetics.h" "Sensors.h" "Effectors.h" Genetics.cpp :///#include“ Genetics.h”“ Sensors.h”“ Effectors.h”

C_Genome::C_Genome(C_Sensors * p_C_SensorsRef, C_Effectors * p_C_EffectorsRef)
: p_Sensors (p_C_SensorsRef),  p_Effectors (p_C_EffectorsRef) {}

When I try to compile this, I get 6 errors of "'class_name' does not name a type" and 6 errors of " ISO c++ forbids declaration of 'class_name' with no type". 当我尝试对此进行编译时,出现6错误“'class_name'未命名类型”和6错误“ ISO c ++禁止声明'class_name'无类型”。 I also have code in main that attempts to initialize some C_Agent objects. 我在main中也有尝试初始化一些C_Agent对象的代码。

如果具有循环依赖关系,则需要在某处至少声明一个类名。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 包含引用或指针的对象向量 - Vector of objects containing references or pointers 我有一个指向对象的向量。 如何释放记忆? - I have a vector of pointers to objects. How to free memory? 指向对象的指针的私有向量。 如何使用getter方法访问那些对象? - A private vector of pointers pointing to objects. How to access those objects with getter method? 类的方法和对象。 参考? 智能指针? 简单的初始化? - Class' methods and objects. Reference? Smart pointers? Simple initialization? 对于由其他对象组成的C ++类,使这些成员对象成为指针是一种好习惯吗? - For a C++ class comprised of other objects, is it good practice to make those member objects pointers? 每个 class 的功能是否在该 class 的对象内具有 function 指针? - Do the functions of each class have function pointers inside the objects of that class? 如何将子类作为期望基类的函数的参数传递,然后将该对象传递到指向这些抽象类对象的指针向量中? - how to pass subclass as parameter for function expecting base class then pass that object into vector of pointers to those abstract class objects? 构造相互引用的对象 - Constructing objects with mutual references to each other 包含引用的对象的向量 - vector of objects containing references C ++-创建指向包含类对象指针的数组元素的指针 - C++ - Creating pointers to elements of an array containing pointers to class objects
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM