Visual Studio检测Operater重载虽然g ++没有

时间:2015-10-27 06:31:59

标签: c++ c++11 visual-studio-2013 g++

我有一个家庭课。我使用house house;初始化一个新的house元素然后我将数据传递给它,然后我cout它:

cout << house;

Couting house在Visual Studio中运行得很好,但出于某种原因,当我尝试使用g ++进行编译时收到此错误:

error: cannot bind ‘std::basic_ostream<char>::__ostream_type {aka std::basic_ostream<char>}’ lvalue to ‘std::basic_ostream<char>&&’

即使我在我的一个头文件中非常清楚地知道这一点:

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

我们非常感谢您提供的任何反馈,因为我看不出g ++无法看到我的运算符重载函数的原因。

编辑:这是我的运算符重载函数:

std::ostream& operator<< (std::ostream& out, const house& house)
{
    //unsigned short i = house->getSqrFt();
    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;
}

这是我的班级:

#ifndef HOUSE
#define HOUSE
class house
{
public:
    house();
    house(const char [], const char [], const short& sqrFt, const float& rating, const float& bathrooms);
    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

0 个答案:

没有答案