vector problem

B

Billy Patton

I have a class method that looks like this:

bool Results(std::vector<std::vector<xy_t>>& out);

xy_t looks like this

typedef struct { long x,y; } xy_t;

THe results would not compile. (linux RH3)
I added
typedef vector<xy_t> *vec_p;

Then I did
bool Results(std::vector<std::vector<vec_p>>& out);

THis compiled fine. What was wrong with the first instance?

___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, (e-mail address removed)
 
V

Victor Bazarov

Billy said:
I have a class method that looks like this:

bool Results(std::vector<std::vector<xy_t>>& out);

xy_t looks like this

typedef struct { long x,y; } xy_t;

THe results would not compile. (linux RH3)
I added
typedef vector<xy_t> *vec_p;

Then I did
bool Results(std::vector<std::vector<vec_p>>& out);

THis compiled fine. What was wrong with the first instance?

I would probably use normal C++ syntax and defined xy_t as

struct xy_t { long x,y; };

And, AFAIK, a space between two closing angle brackets is still
required. So you need

std::vector<std::vector<xy_t> >&

.. Other than that, nothing leaps out.

V
 
A

Andre Kostur

I have a class method that looks like this:

bool Results(std::vector<std::vector<xy_t>>& out);

xy_t looks like this

typedef struct { long x,y; } xy_t;

THe results would not compile. (linux RH3)
I added
typedef vector<xy_t> *vec_p;

Then I did
bool Results(std::vector<std::vector<vec_p>>& out);

THis compiled fine. What was wrong with the first instance?

The C++ compiler will try to make the longest token it can when tokenizing
strings. So, for your parameter type:

std::vector<std::vector<xy_t>> &

The last >> is interpreted as being the right shift (or perhaps the
extraction) operator. You need to put a space in there so that it breaks
up the token:

std::vector<std::vector<xy_t> > &
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top