I haven't programmed in sometime and am rusty. I was never an expert either. I know my code has a simple error but I can't figure out what it is. I was practicing coding when I couldn't determine why the class constructor wasn't working as intended.

#include <iostream>                  
using std::cout;

class CBus
    int year;
    char *model;
    char *make;

    CBus(int a, char *b, char *c);
    bool operator>(CBus &aBus)const;

CBus::CBus(int a = 1995, char *b = Sedan, char *c = Mazda)
    year = a;
    model = b;
    make = c;

bool CBus::operator>(CBus &aBus)const
    return this->year > aBus.year;

int main()

    CBus John(1998, Camry, Toyota);
    CBus Pam(2012, Sedan, Toyota);

    cout << "  "  <<  (Pam>(John));

I underlined and bold the words that intellisense put red lines under in my compiler.

Edited by mike_2000_17: Fixed formatting

6 Years
Discussion Span
Last Post by rubberman

If you mean those underlined variables to be strings, you have to put " around them.

CBus::CBus(int a = 1995, char *b = "Sedan", char *c = "Mazda")


I knew I forgot something. I'll remember to use ' for char. Thanks for the quick response.


Also, use const char* for the make and model. Most compilers will give you an error using string literals for a non-const char pointer.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.