【发布时间】:2015-02-21 19:18:36
【问题描述】:
在过去的一个小时里,我一直试图让这个类拥有一个私有数组数据成员,但它拒绝工作。我不想用 数组[5] 地图数组; 因为那时我没有得到数组成员函数。
这是我目前正在使用的代码。
#include "stdafx.h"
#include <iostream>
#include <array>
#include <fstream>
class Map {
public:
void scanFile();
private:
size_t columns = 20;
size_t rows = 20;
array <int, 5> mapArray;
};
int main() {
Map myMap;
}
以下是我在 Visual Studio 中遇到的一些示例错误。
1>x:\aerofs\gt\ece 2036\lab03\map.cpp(12): error C2143: syntax error : missing ';' before '<'
1>x:\aerofs\gt\ece 2036\lab03\map.cpp(12): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>x:\aerofs\gt\ece 2036\lab03\map.cpp(12): error C2238: unexpected token(s) preceding ';'
【问题讨论】:
-
array类是在std命名空间中定义的,所以试试std::array。 -
谢谢,我没有意识到这个名字实际上来自标准空间。
标签: c++ arrays class initialization