C++ undeclared identifier error

后端 未结 1 1968
忘掉有多难
忘掉有多难 2021-01-26 20:54

I\'m getting an undeclared identifier error and I don\'t know why. I even rewrote the complete stuff to make sure I didn\'t do a typo. Can someone tell me why I got thi

相关标签:
1条回答
  • 2021-01-26 21:07

    This is, as I wrote in the comments, most likely caused by your circular includes. Connection.hpp includes LogicSimulator.hpp which itself includes Connection.hpp.

    In your case, you don't even need the includes. For Pointers and References, a forward declaration is fine:

    Connection.hpp:

    #pragma once
    
    class CircuitObject;
    class LogicSimulator;
    
    class Connection
    {
    public:
        Connection(CircuitObject& c1, CircuitObject& c2, LogicSimulator& 
            simulator);
    private:
        int state;
        CircuitObject& c1;
        CircuitObject& c2;
        LogicSimulator& simulator;
    };
    

    LogicSimulator.hpp:

    #pragma once
    
    #include <SFML\Graphics.hpp>
    #include <vector>
    
    class CircuitObject;
    class Connection;
    
    class LogicSimulator
    {
    public:
        std::vector<CircuitObject*> circuitObjects;
        std::vector<CircuitObject*> selectedCircuitObjects;
        std::vector<Connection*> connections;
        sf::RenderWindow Window;
    
        void Init();
    private:
        void start();
        void draw();
    };
    
    0 讨论(0)
提交回复
热议问题