const vector

Started by
2 comments, last by Zeblar Nagrim 20 years, 5 months ago
How to initialize a const vector? I want to add 2 elements of my Rect class to a vector. Something like this (doesn't work):

const vector<Rect> rects(2) = vector<Rect>(Rect(0,0,333,333),Rect(0,0,333,333));
Please help! [edited by - Zeblar Nagrim on November 15, 2003 4:39:18 AM]
Advertisement
Here is the lazy pachy solution (dono how else to do it, but I bet theres a better way):
vector<Rect> tmp;tmp.push_back(Rect(0,0,333,333));tmp.push_back(Rect(0,0,333,333));const vector<Rect> rects=tmp;


"Stop trying to hit me and hit me!"
Emil Johansen- SMMOG AI designerhttp://smmog.com
quote:Original post by emileej
Here is the lazy pachy solution (dono how else to do it, but I bet theres a better way):
vector<Rect> tmp;tmp.push_back(Rect(0,0,333,333));tmp.push_back(Rect(0,0,333,333));const vector<Rect> rects=tmp;


"Stop trying to hit me and hit me!"


Thanks!

How about:
#include <cstddef>#include <vector>int main() {	const int something_init[] = { 1, 2, 3 };	const std::size_t something_size = sizeof(something_init)/sizeof(*something_init);	std::vector <int> something(something_init, &something_init[something_size]);	// ...}

A bit overly explicit there, just in case...



[edited by - Null and Void on November 15, 2003 4:58:42 AM]

This topic is closed to new replies.

Advertisement