我正在进行一项由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 type
和no '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标志。我做错了吗?