Hello, I have a program where I made an object called Poly to represent a polynomial. There is also a friend function which overloads the operator << so that cout will output a polynomial expression when fed a Poly object. The program is 500 lines long, so I am just showing the relevant parts. The problem lies in main() where what prints to the terminal is different before and after declaring some Poly objects. Why does the problem happen and how do I fix it?
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
class Poly{
private:
//some member variables here
public:
//member function declarations
//some constructors and a destructor
//some member functions here
//some friend functions here
//overloaded << friend function:
The snippet of code that you give doesn't even use the << operator for a polynomial, so it wouldn't have anything to do with it.
Copy your code to a temporary program and reduce it to the minimum compileable example that will reproduce your problem. There is nothing in what you have shown that would cause a problem.
I would hazard a guess that you are going beyond array bounds somewhere, but you haven't shown enough code to diagnose that.
int main()
{
cout << "works good"; //works fine
Poly p1, p2;
cout << "nothing now"; //nothing prints to the terminal
}
If that is your int main() then it doesn't call << for a Poly object, so it is irrelevant whether that output routine is correct or not (although @zapshe conjectures that it wouldn't be if it were used).
But as it stands you are calling a Poly constructor with no arguments.
And you haven't shown us what exactly is in your Poly class, or what a Poly constructor with no arguments would do.