Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

class std::vector has no member named [closed]

Tags:

c++

c++11

#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct coffeeBean
{   
    string name; 
    string country;
    int strength;
};  

std::vector<coffeeBean> coffee_vec[4];

int main(int argc, char ** argv)
{
    coffee_vec[1].name;
    return 0;
}

When I try to run this code I get 'class std::vector<coffeeBean>' has no member named 'name' I thought we can access the struct this way. Am I doing something wrong?

like image 314
rato talo Avatar asked Dec 14 '16 19:12

rato talo


1 Answers

You are creating an array of four vectors, not a vector with four elements.

In your code, coffee_vec[1] refers to a vector<coffeeBean> object, not a coffeeBean object.

like image 185
Mikel F Avatar answered Sep 29 '22 21:09

Mikel F