Error : no operator found

Discussion in 'MFC' started by answerme, Nov 19, 2008.

  1. answerme

    answerme New Member

    Joined:
    Dec 17, 2007
    Messages:
    114
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    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.
     
    Last edited: Nov 19, 2008

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice