Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   Error : no operator found (http://www.go4expert.com/forums/error-operator-t15185/)

answerme 19Nov2008 10:45

Error : no operator found
 
This is my code for the serial port
Code:

BOOL CSerialCom::OpenPort(CString portname)
{
portname= "//./" +portname;

hComm = CreateFile(portname,
                      GENERIC_READ | GENERIC_WRITE,
                      0,
                      0,
                      OPEN_EXISTING,
                      0,
                      0);
        if(hComm==INVALID_HANDLE_VALUE)
        {
                MessageBox("Cannot open Communication Port.Please\nQuit the program and Re-start your PC.","Com Port Error",MB_OK+MB_ICONERROR);
                return false;
        }
                else
                        return true;

}

Iam getting error
Code:

        error C2678: binary '+' : no operator found which takes a left-hand operand of type 'const char [5]' (or there is no acceptable conversion)
Does anyone has solution

xpi0t0s 19Nov2008 21:43

re: Error : no operator found
 
You need to cast "//./" to a CString so that it invokes CString :: operator +(). There is no (char*) :: operator +(), which is what you're trying to invoke.


All times are GMT +5.5. The time now is 03:14.