C++ 超载<&书信电报;,返回ostream会产生错误。C++;

C++ 超载<&书信电报;,返回ostream会产生错误。C++;,c++,operator-overloading,bitwise-operators,return-type,ostream,C++,Operator Overloading,Bitwise Operators,Return Type,Ostream,我对nBlockUse的过载有问题) 我还超载了另一个你用水管冲洗了你的垃圾堆。它可能与当前运行的代码有关,也可能与当前运行的代码无关。尽管我从使用原始指针开始,但在您决定向我们展示的内容中没有任何明显的东西会导致此问题。显示的代码中没有任何东西会导致您描述的问题。“\u BLOCK\u TYPE\u IS\u VALID(pHead->nBlockUse)”错误表示堆在早些时候已损坏,它在return语句中被检测到,但与运算符库中的代码无关,敬请谅解。有道理,我整天都在做另一个项目,没有什么震

我对nBlockUse的过载有问题)


我还超载了另一个你用水管冲洗了你的垃圾堆。它可能与当前运行的代码有关,也可能与当前运行的代码无关。尽管我从使用原始指针开始,但在您决定向我们展示的内容中没有任何明显的东西会导致此问题。

显示的代码中没有任何东西会导致您描述的问题。“\u BLOCK\u TYPE\u IS\u VALID(pHead->nBlockUse)”错误表示堆在早些时候已损坏,它在return语句中被检测到,但与运算符库中的代码无关,敬请谅解。有道理,我整天都在做另一个项目,没有什么震惊,它已经消失了。顺便说一句,你的Car类确实需要一个析构函数、一个复制构造函数和一个operator=,否则当你通过值传递Car对象或以更明显的方式复制它们时,你会出现内存泄漏和/或有趣的错误。
#include "header1.h"
#include <iostream>
using namespace std;

class Car
{
public:
    friend class Extras;
    friend int main();
    friend ostream& operator<< (ostream& os, const Car& in);
    Car();
    Car(string in_name, int in_year, string in_color, float in_cost);
private:
    string name, color;
    int year, extr_num;
    float cost;
    Extras  *extr;
};
int main()
{
    Car c1;
    cout << c1;
    return 0;
}

//Default Constructor
Car::Car()
{
    name = "TEMP";
    color = "BLUE";
    year = 0;
    cost = 0;
    extr = new Extras[3];
    extr_num = 0;
}

//Constructor
Car::Car(string in_name, int in_year, string in_color, float in_cost)
{
    name = in_name;
    color = in_color;
    year = in_year;
    cost = in_cost;
    extr = new Extras[3];
    extr_num = 0;
}

//Overloaded << operator for Car class

//This function is the one that fails.
ostream& operator<< (ostream& os, const Car& in)
{
    os.precision(2);
    os << in.name << ", " << in.year << ", " 
        << in.color << ", $"<< in.cost << ", ";
    os << "extras include: ";
    os << endl;
    return os;  //Line of code in question
}
ostream& operator<< (ostream& os, Extras const &in)
{
    os << in.ex_list;
    return os;
}