Passing STL vectors by reference.

I need to be able to pass a vector by reference, but I keep getting errors saying 'vector' is an undeclared identifier. I've #included it in another part of the program where I'm using them with no problems and have tried 'typedef'ing the vector and putting another #include in this cpp file but nothing works. Here's what I'm trying to do:

[code]
class Node
{
public:
Node();
~Node();
void AddNode(vector & nodeName);
void KillNode();
void AddLink(vector & linkTo);
void KillLink();

private:

};
[/code]

I'm using Visual C++ .Net Thanks in advance.

Comments

  • : I need to be able to pass a vector by reference, but I keep getting errors saying 'vector' is an undeclared identifier. I've #included it in another part of the program where I'm using them with no problems and have tried 'typedef'ing the vector and putting another #include in this cpp file but nothing works. Here's what I'm trying to do:
    :
    : [code]
    : class Node
    : {
    : public:
    : Node();
    : ~Node();
    : void AddNode(vector & nodeName);
    : void KillNode();
    : void AddLink(vector & linkTo);
    : void KillLink();
    :
    : private:
    :
    : };
    : [/code]
    :
    : I'm using Visual C++ .Net Thanks in advance.
    :

    Code looks ok. Perhaps you forgot "using std::vector;"
  • : : I need to be able to pass a vector by reference, but I keep getting errors saying 'vector' is an undeclared identifier. I've #included it in another part of the program where I'm using them with no problems and have tried 'typedef'ing the vector and putting another #include in this cpp file but nothing works. Here's what I'm trying to do:
    : :
    : : [code]
    : : class Node
    : : {
    : : public:
    : : Node();
    : : ~Node();
    : : void AddNode(vector & nodeName);
    : : void KillNode();
    : : void AddLink(vector & linkTo);
    : : void KillLink();
    : :
    : : private:
    : :
    : : };
    : : [/code]
    : :
    : : I'm using Visual C++ .Net Thanks in advance.
    : :
    :
    : Code looks ok. Perhaps you forgot "using std::vector;"
    :

    I've got using namespace std at the top of the other cpp file and tried adding it in this file as well, but it gave me an error. Here's a thought. Do I need to tell the compiler to link my other CPP file to the main one? It will do it automatically, right? I have two CPP files. Main.cpp - has all my windows stuff in it. Then NodeClass.cpp which has the above code. Thanks again.
  • [b][red]This message was edited by Lundin at 2005-2-18 1:30:18[/red][/b][hr]
    : : : I need to be able to pass a vector by reference, but I keep getting errors saying 'vector' is an undeclared identifier. I've #included it in another part of the program where I'm using them with no problems and have tried 'typedef'ing the vector and putting another #include in this cpp file but nothing works. Here's what I'm trying to do:
    : : :
    : : : [code]
    : : : class Node
    : : : {
    : : : public:
    : : : Node();
    : : : ~Node();
    : : : void AddNode(vector & nodeName);
    : : : void KillNode();
    : : : void AddLink(vector & linkTo);
    : : : void KillLink();
    : : :
    : : : private:
    : : :
    : : : };
    : : : [/code]
    : : :
    : : : I'm using Visual C++ .Net Thanks in advance.
    : : :
    : :
    : : Code looks ok. Perhaps you forgot "using std::vector;"
    : :
    :
    : I've got using namespace std at the top of the other cpp file and tried adding it in this file as well, but it gave me an error. Here's a thought. Do I need to tell the compiler to link my other CPP file to the main one? It will do it automatically, right? I have two CPP files. Main.cpp - has all my windows stuff in it. Then NodeClass.cpp which has the above code. Thanks again.
    :

    Usually you tell the linker which cpp files it should link, but some IDE have this feature done automaticly (by adding files to a "project"). It should be done automaticly in .NET. Perhaps you don't have / don't include a NodeClass.h file? Avoid to #include cpp files, it will make the same data linked twice and you will get linker errors.


  • : I've got using namespace std at the top of the other cpp file

    That won't help you in [italic]this[/italic] cpp file. Modules are compiled [italic]separately[/italic]. One at a time.

  • [b][red]This message was edited by Beast96GT at 2005-2-18 23:10:0[/red][/b][hr]
    : : I've got using namespace std at the top of the other cpp file
    :
    : That won't help you in [italic]this[/italic] cpp file. Modules are compiled [italic]separately[/italic]. One at a time.
    :
    :

    Tried that... still errors out... I'm gonna try and put the code in one cpp file. Thanks for the input, guys.

    Plus let me give you guys some insight: I went to college and was taught programming on Solaris box. Now I'm trying to program Windows and it's a bit trickier. Thanks for your patience.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories