Hi,
Is it possible for me to make a vector of POINT's
Something like:
Code:vector<POINT> name;
Thanks
Hi,
Is it possible for me to make a vector of POINT's
Something like:
Code:vector<POINT> name;
Thanks
I don't see any reason that wouldn't work. POINT is a simple struct, so that should work just fine in a vector.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Thats what I thought but I'm getting 2 errors about that line.
Error1: error C2143: syntax error : missing ';' before '<'
Error2: error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
:-S
FYI:
are also present.Code:#include <windows.h> #include <vector>
Any ideas?
Are you by any chance missing a "std::" in front of "vector"?
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Legend
Nice 1
How do I write to a field of the struct?
eg)??Code:name.x.push_back(23)
How do you access a vector op and a struct field at the same time??
Thanks
No, you'd push back a POINT, e.g.
After all, you have a vector of points, not a vector of x's and another vector of y's.Code:POINT p; p.x = 23; p.y = 42; v.push_back(p);
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
You can do that with vector too: Use the "presize" by construction:
Or, you can resize the vector to the size you want:Code:std::vector<T> name(size);
--Code:name.resize(size);
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
You can of course resize as you need it too. So if you know you need 10 more, you do:
It's even more painful if you have to do this without vector (normal C style arrays and/or dynamic memory allocation).Code:size_t size = v.Size(); size_t newsize = size + 10; v.resize(newsize); for(i = size; i < newsize; i++) { v[i].x = i; v[i].y = i * 2; }
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Does POINT have any constructors? Would it allow you to do this?
Code:v.push_back(POINT(23,42));
No, POINT is a standard C type, something like this:
It may use a different integral type (guessing DWORD), but in essence it doesn't have any C++ features.Code:typedef struct _POINT { int x; int y; } POINT;
I guess we could make a proxy object that pretends to be a POINT.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.