1

Here is my header file in Visual C++ Express 2010 (note the last line):

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

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;
    std::vector<int> *currentPosition;
};

I try to assign a value to the vector by using this function;

void LynxRobotArm::setCurrentPosition(int channel, int position)
{
    currentPosition[channel] = position;
}

The compiler gives me an error C2679: binary '=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)

I looked up at MSDN and they say:

To use the operator, you must overload it for the specified type or define a conversion to a type for which the operator is defined.

I tried using currentPosition.at(channel) = position but it did not make a difference.

I am stuck... quite new to pointers, noted that using std::vector<int> currentPosition; instead of std::vector<int> *currentPosition; does not compile.

How should my set-function work? (will try getter afterwards..)

4

0 回答 0