我很好奇一个场景设置如下例:
以下是放在名为Header1.h的文件中的代码:
#ifndef HEADER1_H
#define HEADER1_H
#include "Header2.h"
class Class1
{
Class2 class2Instance;
};
#endif
Run Code Online (Sandbox Code Playgroud)
这是将放在名为Header2.h的文件中的代码:
#ifndef HEADER2_H
#define HEADER2_H
#include "Header1.h"
class Class2
{
Class1 class1Instance;
};
#endif
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我收到错误消息(因为我假设的包含),但感觉我需要这样做才能在每个单独的类中包含每个对象.任何人都可以帮助我实现这个目标,我做错了什么?
我有一个可序列化的模板类:
可序列化.h
#pragma once
#ifndef SERIALIZABLE_H
#define SERIALIZABLE_H
#include "Logger.h"
#include <string>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/exception_ptr.hpp>
template<class T>
class Serializable {
public:
static bool Deserialize(Serializable<T>* object, std::string serializedObject) {
try {
return object->SetValuesFromPropertyTree(GetPropertyTreeFromJsonString(serialized));
} catch (...) {
std::string message = boost::current_exception_diagnostic_information();
Logger::PostLogMessageSimple(LogMessage::ERROR, message);
std::cerr << message << std::endl;
}
}
private:
static boost::property_tree::ptree GetPropertyTreeFromJsonString(const std::string & jsonStr) {
std::istringstream iss(jsonStr);
boost::property_tree::ptree pt;
boost::property_tree::read_json(iss, pt);
return pt;
}
}
#endif // SERIALIZABLE_H
Run Code Online (Sandbox Code Playgroud)
但问题是 Logger 类使用了一个继承自 …