简体   繁体   中英

Vector of Arrays of Objects - push_back()

as name of thread says I have problem with adding elements to my vector... Very similar construction works perfectly (Array of Vectors of Objects)

    Game.h

    class Game: parent, stan
    {
    public:

        (...)
            struct lista_boardow

            {
             stan tabliczka[8][8];
            };


            std::vector<lista_boardow> _lista_boardow;
        (...)

static int AiMove(std::vector<lista_boardow>& vect, stan _b[][8]);

        (...)

And second one:

    Game.cpp

    (...)
int Game::AiMove(std::vector<lista_boardow>& vect, stan tym_board[][8])
{
    stan tabi[8][8];

    (...)

    vect.push_back(tabi); // ?????

    }
    (...)

Error I get:

error C2664: 'void std::vector<_Ty>::push_back(_Ty &&)' : cannot convert parameter 1 from 'stan [8][8]' to 'Game::lista_boardow &&' 

Any ideas?

What kind of problem do you have?

#include <iostream>
#include <vector>
using namespace std;

struct elem {
    int value;
    elem(int value) : value(value) {}
};

struct nih_array {
    elem data[2][2];
};

int main() {
    vector<nih_array> v;
    v.push_back({1, 2, 3, 4});
    cout << v[0].data[1][0].value << endl; // "3", no problem here
}

Live version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM