Help Vector to Function

Hi,
I'm new to C ++ and need help.
I have the task of restructuring to send values to a vector and to pass them from a vector to a function. Visual logs errors.
Please help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int func(vector<Artikl> vektorA)
{
for (int i = 0; i < vektorA.size(); i++)
{
cout << "Sifra: " << vektorA[i].sifra << endl;
cout << "Naziv: " << vektorA[i].naziv << endl;
cout << "Opis: " << vektorA[i].opis << endl;
cout << "Cijena: " << vektorA[i].cijena << endl;

}

return 0;
}

struct Artikl
{
int sifra;
string naziv;
string opis;
int cijena;

Artikl(int s, string n, string o, int c)
{
sifra = s;
naziv = n;
opis = o;
cijena = c;
}

};


int main()
{

Artikl a1(1234, "Tipkovnica", "Mehanicka", 500);
Artikl a2(4321, "Mis", "Laserski", 300);
Artikl a3(1324, "Slusalice", "Bezicne", 400);
Artikl a4(3412, "Printer", "Tintni", 1200);
Artikl a5(1423, "Monitor", "LED", 1800);


vector<Artikl> vArtikli;
vArtikli.push_back(a1);
vArtikli.push_back(a2);
vArtikli.push_back(a3);
vArtikli.push_back(a4);
vArtikli.push_back(a5);




func(vArtikli);
Last edited on
Compiler needs to know what an Artikl object is BEFORE using it.

Move the Artikl struct to BEFORE func
It works.
Thank you very much
Topic archived. No new replies allowed.