我当前正在构建一个应用程序,其中有一个日志函数,该函数在我的大多数类中都可以访问,声明如下:
FileHandler.h
#ifndef FILEHANDLER_H
#define FILEHANDLER_H
#pragma once
#include <SDL.h>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cctype>
//Include to allow logging
#include "log.h"
class fileHandler
{
public:
fileHandler();
virtual ~fileHandler();
void WriteToFile(const std::string& filename, std::string textToWrite);
std::vector<std::string> ReadFromFile(const std::string& filename);
std::string& TrimString(std::string& stringToTrim);
protected:
private:
class log logHandler;
std::vector<std::string> blockOfText;
std::string currentLine;
};
#endif // FILEHANDLER_H
对数
#ifndef LOG_H
#define LOG_H
#pragma once
#include <SDL.h>
#include <string.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <time.h>
class log
{
public:
log();
virtual ~log();
void static WriteToConsole(std::string textToWrite);
void WriteToLogFile(std::string textToWrite);
protected:
private:
};
#endif // LOG_H
很长时间以来,这种方法都运行良好,然后我想在应用程序中的其他位置包含仅与C ++ 11兼容的另一个函数,因此我告诉编译器按照这些标准进行编译。然后,我在“ log logHandler”上收到错误消息,说log不是声明的名称。
通过将行更改为
class log logHandler;
我想知道是否有人可以告诉我在C ++ 03和C ++ 11之间发生了什么变化,我需要这样做吗?
编辑:包括所有相关代码以使问题更加完整。
最佳答案
您没有显示真正的代码(类声明末尾缺少;
,没有#endif
),但是您的问题可能与std::log
有关,而则在C +中收到了新的重载+11,与代码中某处的using namespace std
组合。
请注意,新的过载可能与手头的问题无关;真正的原因很可能是编译器的标准库实现中的某个更改导致内部#include <cmath>
。这意味着即使在C ++ 03中,您的代码也只是巧合地工作,并且始终允许符合标准的C ++ 03编译器拒绝它。
这是一个示例程序,可能会重现您的问题:
#include <cmath>
using namespace std;
struct log
{
};
int main()
{
// log l; // does not compile
struct log l; // compiles
}