In c++, is using a vector of objects a good idea? If not, what’s wrong with this c++ code?
#include <vector>
using namespace std;
class A {};
int main() {
vector<A*> v ( new A);
return 0;
}
from g++:
13: error: invalid conversion from
A*' tounsigned int’
The constructor for std::vector takes an initial length, not an element.
This means you’d normally do:
You’re getting the compiler error you are because, on your system,
size_typeis defined as anunsigned int. It’s trying to use that constructor, but failing, since you’re passing it a pointer to an A.