C++ C和x2B之间的等级差异+;03和C++;11
我目前正在构建一个应用程序,其中我有一个日志函数,可以在我的大多数类中访问,声明如下: FileHandler.hC++ C和x2B之间的等级差异+;03和C++;11,c++,class,c++11,C++,Class,C++11,我目前正在构建一个应用程序,其中我有一个日志函数,可以在我的大多数类中访问,声明如下: FileHandler.h #ifndef FILEHANDLER_H #define FILEHANDLER_H #pragma once #include <SDL.h> #include <string> #include <iostream> #include <fstream> #include <sstream> #include &
#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++03和C++11之间发生了什么变化,需要我这样做
编辑:包括所有相关的代码以使问题更加完整。您没有显示真正的代码(在类声明的末尾缺少
;
,没有#endif
),但您的问题可能与此有关,这在C++11中收到了新的重载,与结合使用命名空间std
在代码中的某个地方
请注意,新的过载可能与当前的问题无关;真正的原因很可能是编译器的标准库实现中的某个地方发生了更改,导致内部#include
。这意味着,即使在C++03中,您的代码也只能在完全巧合的情况下工作,并且始终允许符合条件的C++03编译器拒绝它
下面是一个可能重现您的问题的示例程序:
#include <cmath>
using namespace std;
struct log
{
};
int main()
{
// log l; // does not compile
struct log l; // compiles
}
#包括
使用名称空间std;
结构日志
{
};
int main()
{
//日志l;//未编译
结构日志l;//编译
}
您没有显示真正的代码(在类声明的末尾缺少;
,没有#endif
),但您的问题可能与以下因素有关:在C++11中,它与代码中某处使用命名空间std的相结合,收到了新的重载
请注意,新的过载可能与当前的问题无关;真正的原因很可能是编译器的标准库实现中的某个地方发生了更改,导致内部#include
。这意味着,即使在C++03中,您的代码也只能在完全巧合的情况下工作,并且始终允许符合条件的C++03编译器拒绝它
下面是一个可能重现您的问题的示例程序:
#include <cmath>
using namespace std;
struct log
{
};
int main()
{
// log l; // does not compile
struct log l; // compiles
}
#包括
使用名称空间std;
结构日志
{
};
int main()
{
//日志l;//未编译
结构日志l;//编译
}
您发布的代码的处理方式没有任何变化
我怀疑的是,你在某个地方
这会导致编译器无法明确解析名称log
,因为存在std::log
(函数)和类日志
通过显式声明类日志
,您告诉编译器您引用的是该类。您发布的代码的处理方式没有任何变化
我怀疑的是,你在某个地方
这会导致编译器无法明确解析名称log
,因为存在std::log
(函数)和类日志
通过明确说明类日志
,您告诉编译器您引用的是该类。除此之外还有一个小补充:如果包含
,则日志l代码>即使在C++03中也不起作用。最有可能的是,标准库实现发生了变化,因此在OP的系统上,由于某种原因(这是完全有效的),其他一些头现在隐式地包含了
。@hvd:你是对的,我将把这一点添加到答案中代码>即使在C++03中也不起作用。最有可能的是,标准库实现发生了变化,因此在OP的系统上,出于某种原因(这是完全有效的),其他一些头现在隐式地包含了
。@hvd:你说得对,我将把这一点添加到答案中。至少,你应该在你的问题中包含log.h
的内容!更新了原始帖子,将filehandler.h和log.hAt中的所有代码都包含在内。作为绝对最小值,您应该在问题中包含log.h
的内容!更新了原始帖子,将所有代码包含在filehandler.h和log.h中
#include <cmath>
using namespace std;