Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 752
  • Last Modified:

vector definition in Visual C++

Hi,

I am a programming beginnger. I have a code that was created for a unix platform that I am trying to compile on Visual C++

For Example consider the following in a .h file:

#include <vector>
#include<set>
class FMNode
{
       public:
               FMNodeStatus status;
               unsigned int nChanges;
               unsigned int t_stamp;
       public:
               FMNode () : status (USTAT), nChanges (0), t_stamp (INT_MIN) { };
};

typedef vector<FMNode > FMNodeArray ; //this line gives error

class FMPartitioner
{
       public:
set<unsigned int> , cNets, *aNodes; //this line gives error too and I don't understand what does Set do

void initialize (double ratio, Set <unsigned int> * actNodes, vector <FMNode> * nd);  //this one too gives error

And then in the .cpp file:

void
FMPartitioner :: initialize (double ratio, unsigned int *actNodes,
               vector <FMNode> * nd) //gives error ofcourse
0
nmahmo
Asked:
nmahmo
  • 2
  • 2
2 Solutions
 
AlexFMCommented:
Whar errors exactly?

Just a guess:

#include <vector>
#include<set>
using namespace std;
0
 
AlexFMCommented:
set is STL container. Each element of it must have unique value.

set<unsigned int> , cNets, *aNodes;

defines set of unsigned int elements (cNets) and pointer to such set (aNodes).
0
 
jkrCommented:
Alternatively, you could explicitly refer to the 'vector' from the 'std' namespace, e.g.

typedef std::vector<FMNode > FMNodeArray ;

But, using 'using namespace ...' will save a lot of typing.

0
 
a1programmerCommented:
> what does a set do  ?  
     check this out - http://www.informatik.uni-freiburg.de/~danlee/fun/STL-doc/STL/Set.html#Set


in fmnode.h
----------------------------------------

#include <vector>
#include <set>

using namespace std;

class FMNode
{
       public:
               FMNodeStatus status;
               unsigned int nChanges;
               unsigned int t_stamp;
       public:
               FMNode () : status (USTAT), nChanges (0), t_stamp (INT_MIN) { };
};

typedef vector<FMNode> FMNodeArray;  //this line gives error    <--- notice that this isn't an array.  Call it VFMNode  or something


class FMPartitioner
{
       public:
              set <unsigned int> cNets;  //this line gives error too and I don't understand what does Set do
              set <unsigned int>*aNodes;  
         void initialize (double ratio, Set <unsigned int> * actNodes, vector <FMNode> * nd);  //this one too gives error
};






And then in the .cpp file:
---------------------------------------------------

//you need to include your header file
#include "fmnode.h"

typedef vector<FMNode> VFMNode;   <----------------------------------V            (You can use this from your header file)

void  FMPartitioner :: initialize (double ratio, unsigned int *actNodes,  VFMNode nd) //gives error ofcourse


0
 
a1programmerCommented:
Here's the sgi docs for a SET.  

it needs to be declared like so:
    set<Key, Compare, Alloc>

http://www.sgi.com/tech/stl/set.html
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now