Pie*_*ter 3 c++-cli vector visual-c++
这是我在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;
};
Run Code Online (Sandbox Code Playgroud)
一切正常,直到我改变了最后一行int currentPosition来vector<int> currentPosition.如果我现在尝试编译/调试,我会收到以下错误消息:
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 ';'
Run Code Online (Sandbox Code Playgroud)
我检查了MSDN有关这些错误代码的更多信息,但我无法弄清楚代码有什么问题.有任何想法吗?
vector是在std命名空间中定义的模板,因此您应该编写std::vector<int>而不是vector<int>.
或者你可以using namespace std;在这个文件的开头写,但请注意,这被认为是不好的做法,因为它可能会导致你的类的某些名称变得模糊不清.