467,077 Members | 947 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,077 developers. It's quick & easy.

trouble accessing into a referenced variable

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[i]*.time)
. . .

Nov 13 '06 #1
  • viewed: 997
Share:
4 Replies
"Alan" <ja*********@verizon.netwrote:
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[i].time)
. . .
--
To send me email, put "sheltie" in the subject.
Nov 13 '06 #2

Alan wrote:
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[i]*.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[i].time) i = 0;
}
I am not sure if I misunderstand but I do not know why you are using *

N

Nov 13 '06 #3
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

Nov 13 '06 #4

Alan wrote:
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

Nov 13 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Fernando Rodríguez | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.