too many typedefs

C

cppaddict

Hi,

I currently have a class in which I use all of the following a number
of times (nb: Point is custom class):

std::vector<Point>
std::vector<Point>&
const std::vector<Point>
const std::vector<Point>&

It would make things cleaner if I could use typedefs:

typedef std::vector<Point> Points

However, after making that declaration, I get warnings or errors if I
try things like this:

const Points&
Points&
....etc...

Does that mean I have to make a seperate typedef for each of the four
types generated by using the const and & symbols together with the
original type? If not, what can I do?

Thanks,
cpp
 
V

Victor Bazarov

cppaddict said:
I currently have a class in which I use all of the following a number
of times (nb: Point is custom class):

std::vector<Point>
std::vector<Point>&
const std::vector<Point>
const std::vector<Point>&

It would make things cleaner if I could use typedefs:

typedef std::vector<Point> Points

However, after making that declaration, I get warnings or errors if I
try things like this:

const Points&
Points&
...etc...

Does that mean I have to make a seperate typedef for each of the four
types generated by using the const and & symbols together with the
original type? If not, what can I do?

Is that your first day here? Post your code.

Here is mine, and it compiles just fine:

#include <vector>
class Point {};
class FullOfTypedefs {
typedef std::vector<Point> PointVector;

PointVector regular_vector;
PointVector const const_vector;
PointVector & ref_to_reg_vector;
PointVector const & ref_to_const_vector;
public:
FullOfTypedefs() : ref_to_reg_vector(regular_vector)
, ref_to_const_vector(const_vector) {}
};

int main() {
FullOfTypedefs justToSeeIfICanInstantiateIt;
}


Victor
 
C

cppaddict

Is that your first day here? Post your code.

Here is mine, and it compiles just fine:

Sorry, Victor, you are right. The error was coming from something
else...

cpp
 

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top