Help with default constructor

I can't get this default constructor to work. Essentially it should just be creating a linked list with one node of a value zero. When it runs it won't print out the zero. Here's what I have and the header files I"m using.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "big_number.h"

using namespace std;

// default constructor, creates a 0
big_number::big_number()
{
        head_ptr = new node;
	head_ptr->prev = nullptr;
        head_ptr->next = nullptr;
        head_ptr->data = 0;
        tail_ptr = head_ptr;
}


big_number.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "doubly_linked_list.h"

using namespace std;

class big_number 
{
	public:
	
		// constructors (work like init() methods)
		big_number();
		big_number(int i);
		big_number(const big_number& m);
		big_number(const string& s, unsigned int base);
		
		// assignment operator
		// big_number a = 98; big_number b = 0; ... b = a;
		big_number& operator=(const big_number& m);
		
		// destructor (works like destr() method)
		~big_number();
	
		// self-assigning arithmetic operators
		big_number& operator+=(const big_number& addend);
		big_number& operator-=(const big_number& subtractand);
		big_number& operator*=(const big_number& multiplicand);
		big_number& operator/=(const big_number& divisor);
	
		// positive modulus
		big_number& operator%=(const big_number& divisor);
		
		// overload prefix increment
		big_number& operator++();  
		// overload prefix decrement
		big_number& operator--();  
		
		// input and output operators
		friend std::ostream& operator<<(std::ostream& os, const big_number& bignum);
		friend std::istream& operator>>(std::istream& is, big_number& bignum);
		
		// arithmetic operators
		friend big_number operator+(const big_number& a, const big_number& b);
		friend big_number operator-(const big_number& a, const big_number& b);
		friend big_number operator*(const big_number& a, const big_number& b);
		friend big_number operator/(const big_number& a, const big_number& b);
		friend big_number operator%(const big_number& a, const big_number& b);
		// hard to do without fast multiplication
		friend big_number factorial(const big_number& a);

		// comparison operators
		friend bool operator>(const big_number& a, const big_number& b);
		friend bool operator>=(const big_number& a, const big_number& b);
		friend bool operator<(const big_number& a, const big_number& b);
		friend bool operator<=(const big_number& a, const big_number& b);	
		friend bool operator==(const big_number& a, const big_number& b);
		friend bool operator!=(const big_number& a, const big_number& b);

	private:
	
		node* head_ptr;
		node* tail_ptr;
		unsigned int digits;
		bool positive;
		unsigned int base;
		
		// helper functions can go here
		
};


doubly_linked_list.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

struct node {
	char data;
	node* next;
	node* prev;
};

void add_node(node*& head_ptr, node*& tail_ptr, const char& payload);

bool remove_node(node*& head_ptr, node*& tail_ptr, const char& target);

void print_list(const node* head_ptr);

void print_list_backwards (const node* tail_ptr);

bool find_list(const node* head_ptr, const char& target);

void clear_list(node*& head_ptr, node*& tail_ptr);

void copy_list(const node* source_head_ptr,
	node*& dest_head_ptr, node*& dest_tail_ptr);
I don't see you attempting to print anything out anywhere? Could you show the printing code at least, along with its results?
My mistake.

test_big_num.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "big_number.h"

using namespace std;

int main()
{
	int n1, n2;
	unsigned int base;
	string s;
			
	char choice;
	do
	{
		cout << "Type 'd' to test default constructor" << endl;
		cout << "Type 'i' to test int constructor" << endl;
		cout << "Type 's' to test string constructor" << endl;
		cout << "Type 'a' to test assignment" << endl;
		cout << "Type '>' to test input operator" << endl;
		cout << "Type '=' to test comparison operators" << endl;
		cout << "Type 'q' to quit" << endl;
		cin >> choice;
	
		if (toupper(choice) == 'D')
		{
			big_number a;
			cout << "Default constructor gives " << a << endl;
		}
		
		if (toupper(choice) == 'I')
		{
			cout << "Enter an integer: ";
			cin >> n1;
			big_number b(n1);
			cout << "Int constructor with " << n1 << " gives " << b <<
                        endl;
		}
		
		if (toupper(choice) == 'S')
		{
			cout << "Enter a base: ";
			cin >> base;
			cout << "Enter a string: ";
			cin >> s;
			big_number e(s, base);
			cout << "String constructor with " << s << " in base " << 
				base << " gives " << e << endl;
		}
		
		if (toupper(choice) == 'A')
		{
			big_number e(9);
			big_number d;
			d = e;
			cout << "Assignment of " << e << " to ";
			++e;
			cout << d << " gives " << e << endl;
			if (d == e) cout << "boo, shallow copy";
		}
		
		if (choice == '>')
		{
			big_number n1;
			cout << "Enter a big number: ";
			cin >> n1;
			cout << "You entered " << n1 << endl;
		}
		
		if (choice == '=')
		{
			cout << "Enter a number: ";
			cin >> n1;
			cout << "Enter another number: ";
			cin >> n2;
			big_number f(n1);
			big_number g(n2);
			if (f == g)
				cout << f << " == " << g << endl;
			if (f != g)
				cout << f << " != " << g << endl;
			if (f < g)
				cout << f << " < " << g << endl;
			if (f <= g)
				cout << f << " <= " << g << endl;
			if (f > g)
				cout << f << " > " << g << endl;
			if (f >= g)
				cout << f << " >= " << g << endl;
		}

	} while (toupper(choice) != 'Q'); 
}


When I print I get:

Default constructor gives

I just need it to give me a zero.
What does operator<<() do?
Topic archived. No new replies allowed.