C ++未声明的标识符(但它被声明?)

时间:2010-12-24 19:50:45

标签: c++ undeclared-identifier

我很确定我已经包含了qanda类,但是当我尝试声明包含它的向量或类型的类时,我得到一个错误,说qanda未定义。知道问题可能是什么吗?

bot_manager_item.h

#pragma once

#include "../bot_packet/bot_packet.h"
#include <vector>

class bot_manager_item;
#include "qanda.h"
#include "bot_manager.h"

class bot_manager_item
{
public:
    bot_manager_item(bot_manager* mngr, const char* name, const char* work_dir);
    ~bot_manager_item();

    bool startup();
    void cleanup();
    void on_push_event(bot_exchange_format f);
    bool disable;

private:
    void apply_changes();
    bot_manager *_mngr;

    std::string _name;
    std::string _work_dir;
    std::string _message;
    std::string _message_copy;
    std::vector<qanda> games;
    qanda test;

    char _config_full_path[2600];
};

qanda.h

#ifndef Q_AND_A
#define Q_AND_A

#include "users.h"
#include "..\bot_packet\bot_packet.h"
#include "bot_manager.h"
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <fstream>


class qanda
{
public:
    qanda(bot_manager * manager, std::string name, std::string directory);
    ~qanda(){};
    void room_message(std::string username, std::string user_message);
    void timer_tick();

private:
    // data members
    std::string question;
    std::string answer;
    std::string directory;
    std::string command_prefix;
    std::string name;

    Users users;
    std::map <std::string, std::string> questions_and_answers;

    int time_per_question; // seconds
    int time_between_questions; // seconds
    int timer; // milliseconds

    bool is_delayed;
    bool is_playing;

    bot_manager * manager;

    // functions
    void new_question();
    void send_message(std::string msg);
    void announce_question();
    void load_questions();

};

#endif

解决:我最终以这样的方式重构代码,以避免在qanda类中使用bot_manager。

1 个答案:

答案 0 :(得分:7)

我怀疑是一个循环#include问题。是否有可能qanda.h间接包含bot_manager_item.h?

看起来您可以通过使用前向声明来减少标头依赖性

class bot_manager;
在您发布的一个或两个头文件中

而不是#include "bot_manager.h"