Thread: A Lil Help With Inheritance...

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    24
    error C2677: binary '||' : no global operator found which takes type 'std::string' (or there is no acceptable conversion)

    when i get this error what am i facing?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by frassunit View Post
    error C2677: binary '||' : no global operator found which takes type 'std::string' (or there is no acceptable conversion)

    when i get this error what am i facing?
    Can you post a line or three around that?

    It sounds like you are doing || with one side as a string - which would be a rather strangt thing to do.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    24
    Code:
    bool Vehicle:: Any_Accident(void){
    		string accident;
    		
    		cout<<"\nHas The Vehicle Been through any accidents?"<<"\nYes/No:";
    		cin>> accident;
    			if (accident== "yes" || accident== "Yes"){
    
    
    				return 1;
    			}
    			else 
    				return 0;
    			
    
    		
    }
    OK the error was gone when i used two equal signs cuz i forgot that what am doing is something similar to strcmp...

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    			if (accident== "yes" || accident== "Yes"){
    
    
    				return 1;
    			}
    			else 
    				return 0;
    Why is there braces around the return in the if-side, but not braces in the else-side?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by matsp View Post
    Why is there braces around the return in the if-side, but not braces in the else-side?
    Glad I'm not the only one who gets annoyed by dangling else statements! Personally I always use braces, even if it's a one-liner, but at the very least be consistent for both if and else case!

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 06-08-2009, 03:03 PM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  3. inheritance and performance
    By kuhnmi in forum C++ Programming
    Replies: 5
    Last Post: 08-04-2004, 12:46 PM
  4. Inheritance and Polymorphism
    By bench386 in forum C++ Programming
    Replies: 2
    Last Post: 03-18-2004, 10:19 PM
  5. Inheritance vs Composition
    By Panopticon in forum C++ Programming
    Replies: 11
    Last Post: 01-20-2003, 04:41 AM