1

I've been trying to get this class to have a private array data member for the past hour, but it's refusing to work. I don't want to use array[5] mapArray; because then I don't get the array member functions.

Here is the code I am using at the moment.

#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;
}

And here are some example errors I am getting in 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 ';'
2
  • 2
    The array class is defined in the std namespace, so try std::array. Commented Feb 21, 2015 at 19:20
  • Thanks, I didn't realize the name actually came from the std space. Commented Feb 21, 2015 at 19:23

2 Answers 2

1

You got compilation error. It is because array is defined in namespace std. Either add

using namespace std;

at the top of your file or add std:: before you use any type defined in there:

std::array< int, 5> mapArray;

The latter is preferred because you don't have to bring all symbols from the standard library just to use it's array type.

Sign up to request clarification or add additional context in comments.

Comments

1

Standard STL classes, including std::array, are part of the std:: namespace.

So, you can simply add the std:: namespace qualifier to your array data member:

std::array<int, 5> mapArray;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.