mardi 27 octobre 2015

Visual Studio Compiling & Detecting Operater Overloading While g++ doesn't

I have a house class. I initialize a new house element with house house; then I pass data into it and then I cout it:

cout << house;

Couting house works just fine in Visual Studio, but for some reason, I receive this error when I try to compile with g++:

main.cpp:19:57: error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream<char>::__ostream_type {aka std::basic_ostream<char>}’ and ‘house’)
cout << "\nnext house to be visited:" << endl << endl << house << endl;

Even though I very clearly have this in one of my header files:

friend std::ostream& operator<< (std::ostream& out, house);

Any feedback you can give would be greatly appreciated, as I can see no reason for g++ not being able to see my operator overloading function.

Edit: Here's my operator overloading function:

std::ostream& operator<< (std::ostream& out, const house& house)
{
    out << "Address: " << house.getAddress() << std::endl
        << "Square Feet: " << house.getSqrFt() << std::endl
        << "Bedrooms: " << +house.getBedrooms() << std::endl
        << "Bathrooms: " << house.getBathrooms() << std::endl
        << "Description: " << house.getDescription() << std::endl;
    return out;
}

And here's my house class:

#ifndef HOUSE
#define HOUSE
class house
{
public:
    house();
    house(const char[], const unsigned short& sqrFt, const unsigned char& bedrooms, const float& bathrooms, const char[]);
    house(house & obj);
    house(house *& obj);
    ~house();
    char * getAddress() const;
    unsigned short getSqrFt() const;
    unsigned char getBedrooms() const;
    float getBathrooms() const;
    char * getDescription() const;
    void setAddress(const char address[]);
    void setSqrFt(const unsigned short& sqrFt);
    void setBedrooms(const unsigned char& bedrooms);
    void setBathrooms(const float& bathrooms);
    void setDescription(const char description[]);
    void setEqual(house &, house*);
private:
    char * address;
    unsigned short sqrFt;
    unsigned char bedrooms;
    float bathrooms;
    char * description;
};
#endif

Aucun commentaire:

Enregistrer un commentaire