Queue from struct type
10,636
Solution 1
It sounds like you may have wanted to do this instead:
queue<sudurjanie> q;
sudurjanie item;
cin >> item.stoka_ime;
q.push(item);
The line cin>>q.push(sudurjanie.stoka_ime);
doesn't make any sense. Literally, it means:
- Pass
sudurjanie.stoka_ime
toq
'spush()
method. This will fail, becausepush()
takes an argument of typesudurjanie
while you have supplied an argument of typestring
. - Read from
cin
into the result of thepush()
call, which isvoid
. This will fail because it makes no sense to read intovoid
.
Solution 2
Your reference to sudurjanie.stoka_ime
is invalid as you are naming a member of the type, not an instance of it.
Try:
sudurjanie tmp;
cin >> tmp.stoka_ime;
q.push(tmp);
This will create an instance of sudurjanie
, named tmp
, read the field, then push the instance onto the queue
Author by
Nikolai Cekov
Updated on October 21, 2022Comments
-
Nikolai Cekov over 1 year
Ok, that is my struct:
struct sudurjanie { string stoka_ime; string proizvoditel; double cena; int kolichestvo; };
Next I create queue:
queue<sudurjanie> q;
But when I write this:
cin >> q.push(sudurjanie.stoka_ime);
In error list write this:
IntelliSense: a nonstatic member reference must be relative to a specific object
Ok, when I try this:
cout << q.back();
, why write this:
no operator
"<<"
matches these operands?