c++ - v <int> pos(MAX)v <int> tmp是非类类型 ‘__gnu_cxx::__alloc_traits<std::allocator<int>>::value_type {aka int}’ pos [i] .push_back(tmp);

标签 c++ vector terminal compiler-errors stl

C++(STL):

Request for member ‘push_back’ in ‘pos.std::vector<int>::operator[](((std::vector<int>::size_type)i))’, which is of non-class type ‘__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}’
   pos[i].push_back(tmp);
vector<int> pos(MAX), vector<int> tmp;

我不知道为什么我的代码出错了。
所以,请告诉,为什么会出现此错误

目标:我只能在运行竞赛中为部分代码编写解决方案时才能给出完整的代码,因为我现在正面临这个问题。所以,请
告诉我这个错误。然后,我所有其他代码部分都可以正常工作。

我的密码:
/*
 Name: SUSHANT OBEROI
 College: MNNIT ALLAHABAD
 Email: sushantoberoi3@gmail.com
 Handle: soc3
*/

#include<bits/stdc++.h>
using namespace std;

#define sd(a) scanf("%d", &a)
#define slld(a) scanf("%lld", &a)
#define fl(i, a, b) for(int i=a; i<b; i++)
#define fle(i, a, b) for(int i=a; i<=b; i++)
#define ll long long
#define wl(q) while(q--)
#define MAX 300005
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007

void print_output() {                                                                               
    vector<int> pos(MAX);
    fl(i, 0, 100) {
        pos[i].clear();
        vector<int> tmp;
        fl(j, 0, 100) 
            tmp.push_back(j);
        pos[i].push_back(tmp);
    }
}

int main() {
    print_output();
    return 0;
}

我认为(仅根据我来说,我不正确的答案是什么?)
我做得正确,但编译器是错误的。 (对不起,我这么认为)。

最佳答案

您已经定义了vector<int> pos(MAX);,它是int的 vector 。表达式pos[i]返回对 vector 元素的引用,在这种情况下,该元素是int。语句pos[i].push_back(tmp);尝试在push_back()上调用int成员函数,该函数不是类,并且没有该成员函数。

也许您打算创建vector<vector<int>> pos(MAX);,即 vector 的 vector 。我不知道,看到#include<bits/stdc++.h>和这些#define行之后,我对其余代码不感兴趣。

关于c++ - v <int> pos(MAX)v <int> tmp是非类类型 ‘__gnu_cxx::__alloc_traits<std::allocator<int>>::value_type {aka int}’ pos [i] .push_back(tmp);,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56406414/

相关文章:

c++ - 二叉搜索树插入 C++

c# - 如何在 Maya 中实现 MObject 选择器

c++ - 为 vector 实例化一个模板

node.js - 如何解决 "sequelize: command not found"?

django - 我如何使用 Django 编写在 Internet 上运行的控制台应用程序(即,基于文本并从终端使用)?

c++ - 使用重载的 new 和 delete 运算符跟踪已用内存?

c++ - 使用结构中定义的枚举作为 C++ 中的大小写常量

c++ - Point vector 中的 push_back() 不起作用

Java: vector 的大小(以字节为单位)

vim - 打开 vim 文件并自动替换 ^M