BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

vectors?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
Rory Walsh
Guest





PostPosted: Sat Mar 26, 2005 2:16 pm    Post subject: vectors? Reply with quote



Hi, following on from a previous thread I just tried to run a simple
example application which uses vectors, I added the include<vector> but
I get a 'type name expected' error? Can anyone help me out? I'm asking
some very basic questions here, is this the right place to ask or am I
in the wrong list? Thanks for your help anyhow.


#include <vector>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components

private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);

vector <int> scores(50);
};
Back to top
Rory Walsh
Guest





PostPosted: Sat Mar 26, 2005 2:45 pm    Post subject: Re: vectors? Reply with quote



thanks, now all I need to know is how to pass 50 to the constructor? I
don't know anything about vector's, apart from the fact that I can
insert and delete elements from anywhere without leaving holes. I have
searched the help but I cannot find what I need to do? Can you give me
the syntax? Is this the right syntax:

scores = new std::vector< >;

I just don't know what needs to be passed?


Quote:
Yes, the vector template lives in the namespace std, along with most of
the rest of the standard library. Try:

std::vector< int > scores;

Note you must pass '50' to the constructor of the vector if you want to
create a vector with 50 ints all intialized to 0. You would do that in
the form's constructor, not in the header as you show above.

AlisdairM(TeamB)

Back to top
Duane Hebert
Guest





PostPosted: Sat Mar 26, 2005 2:58 pm    Post subject: Re: vectors? Reply with quote




"Rory Walsh" <rorywalsh (AT) ear (DOT) ie> wrote

Quote:
thanks, now all I need to know is how to pass 50 to the constructor? I
don't know anything about vector's, apart from the fact that I can
insert and delete elements from anywhere without leaving holes. I have
searched the help but I cannot find what I need to do? Can you give me
the syntax? Is this the right syntax:

scores = new std::vector< >;

I just don't know what needs to be passed?

You can't assign a static instance of scores with
new.

Try in your ctor:
scores.resize(50);





Back to top
Rory Walsh
Guest





PostPosted: Sat Mar 26, 2005 3:17 pm    Post subject: Re: vectors? Reply with quote

Great, that's sorted it out. Cheers,
Rory.

Duane Hebert wrote:
Quote:
"Rory Walsh" <rorywalsh (AT) ear (DOT) ie> wrote


thanks, now all I need to know is how to pass 50 to the constructor? I
don't know anything about vector's, apart from the fact that I can
insert and delete elements from anywhere without leaving holes. I have
searched the help but I cannot find what I need to do? Can you give me
the syntax? Is this the right syntax:

scores = new std::vector< >;

I just don't know what needs to be passed?


You can't assign a static instance of scores with
new.

Try in your ctor:
scores.resize(50);





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.