By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,263 Members | 2,640 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,263 IT Pros & Developers. It's quick & easy.

trouble accessing into a referenced variable

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
"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

P: n/a

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

P: n/a
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

P: n/a

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.