Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vector<int> - missing type specifier

This is the header of a class I am 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 currentPosition to vector<int> currentPosition. If I try to compile / debug now, I 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 some more info on these error codes, but I cannot figure out what is wrong with the code. Any ideas?

like image 249
Pieter Avatar asked Jun 13 '26 14:06

Pieter


1 Answers

vector is template defined within std namespace, thus you should write std::vector<int> instead of vector<int>.

Alternatively you could write using namespace std; at the beginning of this file, but note that this is considered bad practice since it could cause some of names of your classes to become ambiguous.

like image 128
LihO Avatar answered Jun 18 '26 00:06

LihO



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!