Vector <int> - missing type specifier

This is the title of the class I'm working on in Visual C ++ Express 2010:

/* custom class header to communicate with LynxMotion robot arm */

#include <vector>
using namespace System;
using namespace System::IO::Ports;

public ref class LynxRobotArm
{
public:
    LynxRobotArm();
    ~LynxRobotArm();
    void connectToSerialPort(String^ portName, int baudRate);
    void disconnectFromSerialPort();
    void setCurrentPosition(int channel, int position);
    int getCurrentPosition(int channel);
    void moveToPosition(int channel, int position);

private:
    void initConnection();
    SerialPort^ serialPort;
    array<String^> ^serialPortNames;
    String^ portName;
    int baudRate;
    vector<int> currentPosition;
};

Everything worked fine until I changed the last line int currentPositionto vector<int> currentPosition. If I try to compile / debug now, I will get these error messages:

error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding ';'

I checked MSDN for more information about these error codes, but I cannot figure out what is wrong with the code. Any ideas?

+3
source share
2 answers

vectoris a template defined in the namespace std, so you should write std::vector<int>instead vector<int>.

using namespace std; , , , , .

+7

. std. /. - . 3 :

#include <vector>
using namespace std; 

, , /, std. .

:

#include <vector>
using std::vector;

. - , . , .cpp, .cpp . , . .h/.hpp . , .hpp , . , , . hpp :

#include <vector>

class myClass{
private:
      std::vector myVector;
};

, , , . .hpp.

0
source

All Articles