对象数组的向量- push_back()

Vector of Arrays of Objects - push_back()

本文关键字:back push 数组 向量 对象      更新时间:2023-10-16

作为线程的名称,我有添加元素到我的向量的问题…非常相似的构造可以完美地工作(对象的向量数组)

    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]);
        (...)

第二个:

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

错误:

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

任何想法?

你有什么问题?

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

活版本。