ivanciprian
ivanciprian

Reputation: 83

Vector within struct within class

So, I have this struct:

struct Articol
{
vector <char*> Nume;
char* Titlu;
int An;
vector <int> Pagini;
};

and this class:

class Bibliografie
{
int nr_art, nr_carti, nr_pagini;
vector <Articol> Articole;
};

and the following line of code:

cout << Object.Articole.Nume[j] << " ";

that generates this error:

error: ‘class std::vector<Articol>’ has no member named ‘Nume’

How can I fix that?

Upvotes: 0

Views: 86

Answers (1)

Fantastic Mr Fox
Fantastic Mr Fox

Reputation: 33854

Articole is a std::vector and std::vector has no member Nume. The error is very clear. You need to get an element from the std::vector Articole:

Object.Articole[x].Nume[j]

Just make sure that element at index x exists (or use .at( or iterators or anything else, see std::vector here).

Upvotes: 3

Related Questions