C++ 错误:与‘;不匹配;操作员<<’;

C++ 错误:与‘;不匹配;操作员<<’;,c++,compiler-errors,operator-overloading,C++,Compiler Errors,Operator Overloading,这是我的操作符更新:原来我的头文件以前已经编译过了,所以我对它所做的任何更改都没有通过。一旦我删除了.gch文件,FileDirTest最终被编译。参数obj应该是一个const引用。这肯定不是你测试打印出来的内容的方式。另外,你知道的相对优先级是什么吗?那么我如何用cout检查正确的输出?也许是这样的?库特 std::ostream& operator<< (std::ostream &out, FileDir &obj) { out <<

这是我的操作符更新:原来我的头文件以前已经编译过了,所以我对它所做的任何更改都没有通过。一旦我删除了.gch文件,FileDirTest最终被编译。

参数
obj
应该是一个
const
引用。这肯定不是你测试打印出来的内容的方式。另外,你知道
的相对优先级是什么吗?那么我如何用cout检查正确的输出?也许是这样的?库特
std::ostream& operator<< (std::ostream &out, FileDir &obj) {    
out << obj.toString();    
return out;
}
std::ostream& operator<< (std::ostream &out, FileDir &obj);
assert(cout << t1 == "testFileOne 50kb");
error: no match for ‘operator<<’ (operand types are ‘std::ostream {aka std::basic_ostream<char>}’ and ‘FileDir’)
assert(cout << t1 == "testFileOne 50kb");
 #include <sstream>

class FileDir {

public:
    FileDir();
    FileDir(std::string nameVal, long sizeVal = 4, bool typeVal = false);
    FileDir(const FileDir &obj);
    ~FileDir();            // destructor
    long getSize() const;
    std::string getName() const;
    bool isFile() const;
    std::string rename(std::string newname); 
    long resize(long newsize);
    std::string toString();
    bool operator== (const FileDir &dir1);
    bool operator<(const FileDir &obj);   

private:
    std::string name;
    long size;
    bool type;
};

std::ostringstream& operator<< (std::ostringstream &out, FileDir &obj);
std::string FileDir::toString()

{
    std::string whatever;
    std::stringstream converter;
    converter << size;
    converter >> whatever;

std::string combined;

if (type == false) { 
    combined = name + " " + whatever + "kb";
}

if (type == true) {
    combined = name + "/" + " " + whatever + "kb";
}

return combined;
}
static void OperatorsTest() {

        FileDir t1("testFileOne", 50, false);
        FileDir t2("testDirectory", 100, true);
        FileDir t3("testFileTwo", 20, false);
        assert(t1 < t2);
        assert(t3 < t2);        

        std::ostringstream oss; 
        oss << t1;
        assert(oss.str() == "testFileOne 50kb");        

    }