what do u mean by this code below?
1)vector<int> V(alpha);
2)vector<int> V(vector<int>)

Whats tat declaring? Its not normal vector declaration. Plz help. Thnx

Recommended Answers

All 5 Replies

Actually, it is a normal vector declaration. std::vectors are a templated class. To instantiate a vector you pass a type to the template. Might want to read up on templates. In this case the code looks to be function prototypes. The first function returns a vector of int's and takes alpha which I'm assuming is a user-defined type. and the second is an overload of the same function to take a vector of ints.

The first one looks like a declaration of a vector of ints of size alpha, if alpha is an int---or something that acts like an int. The second parameter to the constructor has the default value.

I have no idea what the second is attempting to do. Wild guesses might be a copy constructor or 2 dimensional vector of ints. If it's valid, it's nothing I've seen before and it's not something I could find in my reference. My reference does give this as a copy constructor:

vector<int> v(v2);

for a vector of ints where v2 has already been declared as type vector<int>, if I interpret my reference correctly. The actual version in my reference looks like:

vector <T> (const vector& c);

I don't see how you could declare both the vector you want to copy into a new vector and the new vector at the same time, as it seems to be trying in the OP, however.

The first one looks like a declaration of a vector of ints of size alpha, if alpha is an int---or something that acts like an int. The second parameter to the constructor has the default value.

I have no idea what the second is attempting to do. Wild guesses might be a copy constructor or 2 dimensional vector of ints. If it's valid, it's nothing I've seen before and it's not something I could find in my reference. My reference does give this as a copy constructor:

vector<int> v(v2);

for a vector of ints where v2 has already been declared as type vector<int>, if I interpret my reference correctly. The actual version in my reference looks like:

vector <T> (const vector& c);

I don't see how you could declare both the vector you want to copy into a new vector and the new vector at the same time, as it seems to be trying in the OP, however.

At first I thought initializations of constructor/copy constructor but it looks more just like function prototypes.

I could go with prototypes. The reason I felt not was use of specific types in the template declaration rather than generic class name, that is vector<int> instead of vector<T>. Knowing the source of the code snippets and knowledge of intent of the author would probably help sort it out a little better.

guys thank u very much..../ i ll try to dig more on this and get back if i cudnt ! Thnx for ur efforts though !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.