从另一个文件访问别名c++

问题描述 投票:0回答:1

我试图从另一个名为

"cph.h"
的文件访问别名,并在 Visual Studio 上的当前文件
"wsManager.h"
中使用它,但编译器会抛出以下错误

Error C2653 'json': is not a class or namespace name

cph.h 文件

#pragma once

#include <boost/beast/core.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/beast/http.hpp>
#include <boost/beast/ssl.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/strand.hpp>

#include <json.hpp>
#include <windows.h>
#include <MT4ManagerAPI.h>
#include "mt4Manager.h"
#include "wsManager.h"

using json = nlohmann::json;

wsManager.h

#pragma once
#include "chp.h"
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/spdlog.h"
#include <iostream>
#include <string>

namespace beast = boost::beast;
namespace http = beast::http;
namespace websocket = beast::websocket;
namespace ssl = boost::asio::ssl;
namespace asio = boost::asio;
using tcp = boost::asio::ip::tcp;


class wsManager
{
 .....
    void postProcessData(beast::flat_buffer bufferData) {
        // Error here
        json json_buffer_data = json::parse(beast::buffers_to_string(bufferData.data())); <- error at this line

        wsResponseData.instrument = json_buffer_data["instrument_id"].dump();
        for (const auto& obj : json_buffer_data["bids"]) {
            wsResponseData.bids = obj["price"];
        }

        for (const auto& obj : json_buffer_data["asks"]) {
            wsResponseData.asks = obj["price"];
        }
    }
};
c++
1个回答
0
投票

正如 @drescherjm 所提到的,只需删除头文件并防止循环包含循环即可解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.