g ++ 6.2默认标准要求最后包含自定义标题吗?

时间:2016-12-02 01:25:03

标签: c++ g++ header-files

我正在进行一项由3个文件组成的简单练习; main.cpp,mapgrid.hpp和mapgrid.cpp;如下:

的main.cpp

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include "mapgrid.hpp"

/* main program code */

mapgrid.hpp

#ifndef MAPGRID_HPP
#define MAPGRID_HPP

#include <vector>

struct Point { /* stuff */ };

class MapGrid { /* stuff */ };

#endif // MAPGRID_HPP

mapgrid.cpp

#include "mapgrid.hpp"

#include <cmath>
#include <algorithm>

/* implementation for Point and MapGrid */

当我尝试在没有指定标准的情况下在g ++ 6.2.0中编译上面的文件时,我收到编译错误,说Point does not name a typeno 'bool MapGrid::walkForward(int, bool)' member function delcared in bool MapGrid::walkForward(int, bool)

奇怪的是,如果我在mapgrid.cpp中切换#includes以使mapgrid.hpp最后出现,程序将正确编译并运行:

#include <cmath>
#include <algorithm>

#include "mapgrid.hpp"

或者如果我使用-std = c ++ 14或-std = c ++ 11标志。我做错了吗?

0 个答案:

没有答案