18

Embarrassingly simple problem here. I am trying to use std::array and am tripping at the first hurdle with the error ...

implicit instantiation of undefined template 'std::__1::array<char,10>'

The code that gives the error is shown below. I can work around it with std::map for now, but I'm sure the fix must be simple!!

enum  p_t   {
    EMPTY = 0
    ,BORDER_L
    // ...
    ,BORDER_BR
    ,DATUM
    ,NUMEL    };

class PlotChars
{
    array<char, p_t::NUMEL> charContainer;
    // error on this ^ line:
    //   implicit instantiation of undefined template 'std::__1::array<char,10>'
};
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
learnvst
  • 15,455
  • 16
  • 74
  • 121

3 Answers3

60

My first guess would be that you simply forgot to:

#include <array>

...before trying to use the array template. While you can (at least indirectly) use a few classes without including the headers (e.g., the compiler can create an std::initializer_list from something like {1, 2, 3} without your including any headers) in most cases (including std::array) you need to include the header before using the class template.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
2

You are using a C-style enum, so you probably need to omit the enum name, if your compiler isn't fully C++11 compliant.

array<char, NUMEL> charContainer;

This works on gcc 4.4.3, whereas the equivalent to your code does not yet work on that version (but does on later ones)

#include <array>

enum XX { X,Y,Z };

struct Foo
{
  std::array<char, Y> a;
};

int main()
{
  Foo f;
}
juanchopanza
  • 223,364
  • 34
  • 402
  • 480
1

Try with that

 std::array<char, (int)NUMEL> charContainer;
benjarobin
  • 4,410
  • 27
  • 21
  • I see where you are going. This would be the solution if I were using `enum class ...` over plain `enum ...` – learnvst Dec 20 '12 at 17:02