For Programmers: Free Programming Magazines  


Home > Archive > Visual Studio > June 2005 > Using STL objects in default setup (VS .NET).









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Using STL objects in default setup (VS .NET).
Josh McFarlane

2005-06-08, 4:00 pm

Ok, I've sat here and fought with the compiler for a while now.

I'm attempting to define a vector, but it keeps giving me a
'CRawData::vector' : missing storage-class or type specifiers
error for the line:
vector<float> vecElevationLeft ; //Vector list of left elevation
samples

I figure I'm missing something fairly easy that is preventing me from
using stl::vector. Anyone care to clue me in on my stupidity?

Thanks,
Josh McFarlane

Jeff F

2005-06-08, 4:00 pm

Josh McFarlane wrote:
> Ok, I've sat here and fought with the compiler for a while now.
>
> I'm attempting to define a vector, but it keeps giving me a
> 'CRawData::vector' : missing storage-class or type specifiers
> error for the line:
> vector<float> vecElevationLeft ; //Vector list of left elevation
> samples
>
> I figure I'm missing something fairly easy that is preventing me from
> using stl::vector. Anyone care to clue me in on my stupidity?


#include <vector>

....

class CRawData
{
....

std::vector<float> vecElevationLeft;

};

Jeff Flinn


Josh McFarlane

2005-06-08, 8:58 pm

Thanks, for some reason one of the other programs I was working on had
the std namespace messed up so I could use vectors without std::vector,
no clue why... just worked.

Got the vectors working in this program now! Thanks =)

Jeff F

2005-06-09, 4:00 pm

Josh McFarlane wrote:
> Thanks, for some reason one of the other programs I was working on had
> the std namespace messed up so I could use vectors without
> std::vector, no clue why... just worked.
>
> Got the vectors working in this program now! Thanks =)


All standard libbrary components(including anything referred to as stl) are
in namespace std. It is often best to explicitly qualify these. In some
cases you can bring the contents of any or all items from a namespace into
the current scope. This should be done with full knowledge of the
implications. A basic rule is to never do this in any file that can be
#included. A better solution often is to use typedefs.

For example in a function definition in a cpp file:

#include <vector>
#include <map>
#include <list>

typedef std::vector<int> tInts;

void somefnc()
{
tInts lInts(10,-1);

...
}

void someotherfnc()
{
using namespace std:

tInts lInts(10,-1);

list<int> lList;

copy( lInts.begin(), lInts.end(), back_inserter(lList) );
}

Jeff Flinn


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com