vectors in c++...!?

Started by
3 comments, last by JaZsT 22 years, 6 months ago
Hello people!! I am having some problems using vectors. First I do this: #include using namespace std; ....so that I can use vectors. Then I create a vector like this: vector MC(10); .....but that doesn''t work. I get compile errors like this: error C2784: ''bool __cdecl std:perator <(const class std::reverse_iterator<`template-parameter-1'',`template-parameter-2'',`template-parameter-3'',`template-parameter-4'',`template-parameter-5''> &,const The point is, that I get those errors only if I pass my own class as an argument to vector. If I pass int for example,it compiles without errors. Myclass I am passing has got default constructor ( MyClass(){} ) and destructor( ~MyClass(){} ). Please help !!!! Thanx !! -- Uros Life lived unexplored is life not worth living !
Life lived unexplored is life not worth living !
Advertisement
try:
vector MC(10);
Since vector is a template you have to specify the type you want the array(vector) to be made of.

If you want an array of 10 integers you''d have to do this:

vector MC(10);

if you want an array of 10 floats you''d have to do this:

vector MC(10);

and so on...
Since vector is a template you have to specify the type you want the array(vector) to be made of.

If you want an array of 10 integers you''d have to do this:

  vector<int> MC(10);//if you want an array of 10 floats you''d have to do this:vector<float> MC(10);  


and so on...
Keep a vector of MyClass pointers, it''s just easier that way. Make sure to new and delete them...
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement