 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Amit Bhatia Guest
|
Posted: Thu Mar 04, 2004 9:57 pm Post subject: Vector and Pairs: a minor query. |
|
|
Hi,
I am not sure but isn't this kind of declaration valid?
vector<pair > A;
Also isn't it valid to use vectors in method declarations/definitions
of a class like
classA::method1(vector<double> &a, bool b)
{
\
}
thanks,
regards,
amit bhatia.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Tom Plunket Guest
|
Posted: Fri Mar 05, 2004 10:44 am Post subject: Re: Vector and Pairs: a minor query. |
|
|
Amit Bhatia wrote:
| Quote: | I am not sure but isn't this kind of declaration valid?
|
Sure. Do you have a compiler? Have you tried compiling it?
Yeah, but people often use typedefs for each sub-bit so that the
declaration is easier to understand. I see that and I wonder,
what in the heck is A, actually?
E.g.
typedef vector<int> NumberList;
typedef pair<double*, NumberList> WeightedNumberList;
typedef pair<int, WeightedNumberList> SomethingImNotSure;
typedef vector<SomethingImNotSure> A;
| Quote: | Also isn't it valid to use vectors in method declarations/definitions
of a class like
classA::method1(vector<double> &a, bool b)
{
\
}
|
Sure, same questions as my first line of response.
-tom!
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
horape@tinuviel.compendiu Guest
|
Posted: Fri Mar 05, 2004 10:46 am Post subject: Re: Vector and Pairs: a minor query. |
|
|
| Quote: | I am not sure but isn't this kind of declaration valid?
vector<pair > A;
|
Yes (are you sure you want a double*?)
| Quote: | Also isn't it valid to use vectors in method declarations/definitions
of a class like
classA::method1(vector<double> &a, bool b)
{
\
}
|
It is valid.
Saludos,
HoraPe
---
Horacio J. Peņa
[email]horape (AT) compendium (DOT) com.ar[/email]
[email]horape (AT) uninet (DOT) edu[/email]
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
NJS Guest
|
Posted: Fri Mar 05, 2004 2:34 pm Post subject: Re: Vector and Pairs: a minor query. |
|
|
Amit Bhatia <bhatia2 (AT) nospam (DOT) co> wrote
| Quote: | Hi,
I am not sure but isn't this kind of declaration valid?
vector<pair > A;
|
You are missing a closing greater than bracket before the "A". Toss
that in and the statement is perfectly legal, but hideous.
I hope that this is coming out of curiousity, rather than real code.
Otherwise, you should probably reevaluate how you are approaching the
problem. If you absolutely must use this data structure layout, then
encapsulating the ugliness into one class might be a good idea.
| Quote: | Also isn't it valid to use vectors in method declarations/definitions
of a class like
classA::method1(vector<double> &a, bool b)
{
\
}
|
Yes, this is legal. In production code, you might add const keywords,
if appropriate. Also, you might want to take a look at the following
article by Hyslop and Sutter, which gives a neat, self-documenting
alternative to the mystery bool parameter:
http://www.cuj.com/documents/s=7977/cujcexp2011hyslop/
Cheers,
Niek Sanders
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Amit Bhatia Guest
|
Posted: Sat Mar 06, 2004 12:03 am Post subject: Re: Vector and Pairs: a minor query. |
|
|
Thanks,
The reason for this weird looking and pretty long data structure
is that this happens to be returned from a method which calculates,
a boolean, a distance (double) and the pointer to the faces of a
convex hull.
I put in double* to avoid the details.
Yes, I agree that typedef will be better idea.
| Quote: | vector<pair > A;
Yeah, but people often use typedefs for each sub-bit so that the
declaration is easier to understand. I see that and I wonder,
what in the heck is A, actually?
classA::method1(vector<double> &a, bool b)
|
Why doesn't this mean that this function always takes in a vector
of size 0 ? Although I want it to take in something of non zero size.
regards,
amit.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Tom Plunket Guest
|
Posted: Sun Mar 07, 2004 10:27 am Post subject: Re: Vector and Pairs: a minor query. |
|
|
Amit Bhatia wrote:
| Quote: | The reason for this weird looking and pretty long data structure
is that this happens to be returned from a method which calculates,
a boolean, a distance (double) and the pointer to the faces of a
convex hull.
I put in double* to avoid the details.
|
Ok, so still- use typedefs for each part, and it will be easier
to understand.
| Quote: | classA::method1(vector<double> &a, bool b)
Why doesn't this mean that this function always takes in a vector
of size 0 ? Although I want it to take in something of non zero size.
|
That doesn't mean that the vector is size zero because you have
no idea how big the vector is that you're passing. The question
is like asking, "so why doesn't this mean that this function
always takes in a boolean with the value false?" You're passing
the parameters, so pass whatever you want to pass, as long as the
types match.
Now stylistically, there's another issue. You'll have to
discover the right thing on your own based on your own
environment, but it could get hairy if the method assumes that
the vector is empty, or assumes that it should clear it first, or
so on and so forth.
Good luck,
-tom!
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
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
|
|