Ill formatted array

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <array>

const int MAP_X = 3;
const int MAP_Y = 4;

template<typename T>
class Tile
{
public:
    Tile( T t ) : mTile(t) {};
    T & operator() () { return mTile; }
    void operator() (const T & tile) { mTile = tile; }
private:
    T mTile;
};

int main()
{
    //Tile<char> map[MAP_X][MAP_Y]
    std::array< std::array< Tile<char>,MAP_Y >, MAP_X> map;
}

I get this error:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
ile.cpp: In function ‘int main()’:
tile.cpp:19:56: error: use of deleted function ‘std::array<std::array<Tile<char>, 4>, 3>::array()’
     std::array< std::array< Tile<char>,MAP_Y >, MAP_X> map;
                                                        ^~~
In file included from tile.cpp:1:0:
/usr/include/c++/7/array:94:12: note: ‘std::array<std::array<Tile<char>, 4>,
3>::array()’ is implicitly deleted because the default definition would be ill-
formed:
     struct array
            ^~~~~
/usr/include/c++/7/array:94:12: error: use of deleted function
 ‘std::array<Tile<char>, 4>::array()’
/usr/include/c++/7/array:94:12: note: ‘std::array<Tile<char>, 4>::array()’ is
 implicitly deleted because the default definition would be ill-formed:
/usr/include/c++/7/array:94:12: error: no matching function for call to 
‘Tile<char>::Tile()’
tile.cpp:10:5: note: candidate: Tile<T>::Tile(T) [with T = char]
     Tile( T t ) : mTile(t) {};
     ^~~~
tile.cpp:10:5: note:   candidate expects 1 argument, 0 provided
tile.cpp:7:7: note: candidate: constexpr Tile<char>::Tile(const Tile<char>&)
 class Tile
       ^~~~
tile.cpp:7:7: note:   candidate expects 1 argument, 0 provided
tile.cpp:7:7: note: candidate: constexpr Tile<char>::Tile(Tile<char>&&)
tile.cpp:7:7: note:   candidate expects 1 argument, 0 provided


Any idea what's wrong with?
Add a constructor with no arguments:
Tile() {};
above your constructor with one argument, and you will be fine.

Declaring a constructor with one argument deletes the default constructor.
Thank you!
Topic archived. No new replies allowed.