DEADLINE AT 12 PLEASE HELP

Basically can't get my program to compile. Its saying that my member functions are not members of my class. I have no idea why...

Here is the class definition:

1
2
3
4
5
6
7
8
9
10
class Bigint
{ public:
	Bigint();
	Bigint(int x);
	Bigint(string s);
	Bigint operator+(const Bigint& b) const;
	string str() const;
  private:
	vector<int> val;
};




here is the member function:

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
Bigint:: operator+ (const Bigint& b) const

{

int size_a = val.size();
int size_b = b.val.size();

vector<int>store;
if (size_a > size_b)
store.resize(size_a);
else
store.resize(size_b);

int temp1;
int temp;
int i = 0;
int carry = 0;
while (i <= size_b-1)
{


temp = val.at(i) + b.val.at(i) + carry;

cout << i << endl;

carry = 0;

if (temp == 10)
{
	carry = 1;
	temp1 = 0;
	store.at(i) = temp1;

}
else if (temp > 10)
{
	carry = 1;
	temp1 = (temp - 10);
	store.at(i) = temp1;

}
else
	store.at(i) = temp;
i++;
}


if (carry > 0)
	store.push_back(carry);

string output;
int p = (val.size()-1);
while (p >= 0)
{
string temp;
stringstream ss;
ss << val.at(p);
temp = ss.str();
output = output + temp;
p--;
}
return Bigint(output);
}




this is the other one that isn't working:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Bigint:: string str() const
{
string output;
int p = (val.size()-1);
while (p >= 0)
{
string temp;
stringstream ss;
ss << val.at(p);
temp = ss.str();
output = output + temp;
p--;
}
return output;
}


The member functions all have const involved so maybe its something todo with that???

thanks.
Last edited on
This Bigint:: operator+ (const Bigint& b) const must be Bigint Bigint:: operator+ (const Bigint& b) const

This Bigint:: string str() const must be string Bigint::str() const
you absoloute star.
Bigint:: string str() const
should be
string Bigint::str() const
string is the return type, and return types go on the front.

Bigint:: operator+ (const Bigint& b) const
should be
Bigint Bigint::operator+ (const Bigint& b) const
It returns a Bigint, and return types go on the front.

Edit: Gargh! Beaten to the punch my my lazy typing :)
Last edited on
Yeah thanks anyway though. One more question, i have been given a main function code by my gremmy school and it contains the function assert. The compiler is chucking this out because its not defined. Do i have to include any libraries to use assert?
assert lives in <cassert>
Topic archived. No new replies allowed.