trouble accessing into a referenced variable

A

Alan

I`m having trouble figuring out the correct syntax for accessing an
element of a struct variable (t_list) passed by reference to a
function. The compiler does not like the code below when I added the
"&" in the call and the "*" in the body of the function. It provides
the error: "expected primary-expression before '.' token"

How do you properly use a variable passed by reference to access
into its structure?

Thanks in advance, Alan

struct report
{
int time;
double xcor; double ycor; double speed;
};

void add_report (report t, vector<report>& t_list)
{
bool found = false;
for (int i = 0; i < t_list*.size(); i++)
if (t.time == t_list*.time)
. . .
 
D

Daniel T.

Alan said:
I`m having trouble figuring out the correct syntax for accessing an
element of a struct variable (t_list) passed by reference to a
function.

See below:
struct report
{
int time;
double xcor; double ycor; double speed;
};

void add_report (report t, vector<report>& t_list)
{
bool found = false;
for (int i = 0; i < t_list.size(); i++)
if (t.time == t_list.time)
 
N

Nindi

Alan said:
I`m having trouble figuring out the correct syntax for accessing an
element of a struct variable (t_list) passed by reference to a
function. The compiler does not like the code below when I added the
"&" in the call and the "*" in the body of the function. It provides
the error: "expected primary-expression before '.' token"

How do you properly use a variable passed by reference to access
into its structure?

Thanks in advance, Alan

struct report
{
int time;
double xcor; double ycor; double speed;
};

void add_report (report t, vector<report>& t_list)
{
bool found = false;
for (int i = 0; i < t_list*.size(); i++)
if (t.time == t_list*.time)


This works for me

struct report
{
int time;
double xcor; double ycor; double speed;
};

void add_report (report t, vector<report>& t_list)
{
bool found = false;
int i =0;
for (int i = 0; i < t_list.size(); i++)
if (t.time == t_list.time) i = 0;
}


I am not sure if I misunderstand but I do not know why you are using *

N
 
A

Alan

Daniel,
Thanks! All the simpler examples of passing by reference
had examples like:

In function declaration: int& a

In function body: a* = 2

so I thought I needed it here. Duh! Alan
 
N

Nindi

Alan said:
Daniel,
Thanks! All the simpler examples of passing by reference
had examples like:

In function declaration: int& a

In function body: a* = 2

so I thought I needed it here. Duh! Alan

no .. a*=2 is actualy a=a*2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top