function prototype

A

Art Cummings

Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the newsgroup FAQ.




Also, see this:

<http://www.caliburn.nl/topposting.html>




Brian

Gotcha, I think this is what you mean. Trust me Brian, i'm not trying to be
rude, just trying to learn the correct etiquete and to follow.

Thanks

Art
 
J

James Kanze

I'm trying to write a function prototype that includes an
array of structures. I'm not sure how to write it. I'm also
not sure what the call to a function that uses this prototype
would look like. From what i've read on the web, it needs to
be a pointer to an array. I'm not sure even where to begin.

void
f( std::vector said:
I've written function protoypes for arrays and 2d arrays but
when I write it for the structure, i get compiler errors.

C++ doesn't have 2D arrays. It emulates them with arrays of
arrays. So you can use something like:

void
f( std::vector< std::vector< SomeStruct > >& arg ) ...

Most of the time, however, for a 2D array, I'd write my own
class, probably using a 1D array (std::vector< T >), and
calculating the linear index.
 
J

James Kanze

Thanks Brian, we haven't dealt with vectors yet.

In which case, you certainly shouldn't have dealt with C style
arrays. About the only time you use C style arrays in C++ is
when you need a POD, or for interfacing with legacy or C code.
All of which qualify as special cases, to be aborded once you're
fully at home with the basics of the language (including
std::vector).

std::vector, of course, should be introduced about the same time
you learn loop constructs.
 
J

James Kanze

Art said:
Thanks Lr, thanks everyone. I'm still not getting how to do this. [..]
void getInfo(Student[],int);
void getInfo(Student &s,int x)
{
}
The two declarations have to MATCH.

Actually, they don't, at least not textually. Something like:

void getInfo( Student[], int ) ;

and then

void getInfo( Student*, int ) ;

is perfectly legal.

It's also a very good example of why C style arrays are broken,
and should only be used when you absolutely need to.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top