| newB c PlusPlusGuy (13) | |
|
I need help with a few things... If someone can PM me, I would sincerely appreciate it. TY | |
|
|
|
| Athar (4466) | |
|
That's not how forums work. Post the problem here and people will give an answer. | |
|
|
|
| newB c PlusPlusGuy (13) | |
| Trying to declare stand-alone friend function, and everything is complaining. Public, private, outside of scope and right below the Class declaration. Still have compiler complaints. | |
|
Last edited on
|
|
| TTT (52) | |
| Put the whole code | |
|
|
|
| newB c PlusPlusGuy (13) | |||
| |||
|
|
|||
| Athar (4466) | |||||
friend functions are not member functions (if they were, they wouldn't need to be friends with the class in the first place), so:void Reset(Number &t)This is not going to work either, because num and twiceNum aren't static members:
Why are you trying to make it a friend function anyway? Either make it a member function or use the public interface (setNum...) to reset the values - there is no need for the friend keyword here. Also, you can't specify a default value both in the declaration and definition of a function:
| |||||
|
Last edited on
|
|||||
| Stewbond (1843) | ||||
When I try and compile, these are the errors I get:
1) you can only define a default value for a function in the declaration. change: Number::Number(int n = 0)to: Number::Number(int n)2) friend only needs to be used inside of a class. Outside it doesn't matter. change: friend void Number::Reset(Number &t)to: void Number::Reset(Number &t)3) Now we come accross another problem. Reset is not a member of Number. If it was, then we wouldn't need the friend function. Because it isn't a member, we should do this: void Reset(Number &t)4&5) Since Reset is declared as a friend in the Number class, it can access the private members of t as if they were public. That means that we don't need those funny Number:: scopes which is causing 2 more errors. Change the whole function to:
| ||||
|
Last edited on
|
||||
| TTT (52) | ||||
|
You should read about friend functions because you have wrong ideas about it Friend functions ARE NOT MEMBER FUNCTIONS so you cannot define it by specifing
So you should define it in such way:
| ||||
|
|
||||
| TTT (52) | |||
|
But there are a lot of other mistakes in your code. Read it carefully again. 1.In friend function body you have written
but num and twicenum are not static members. 2.operator +, operator ++ functions do not return values. 3.You've redefined default argument in constructor | |||
|
Last edited on
|
|||
| Stewbond (1843) | |||
|
To help you out with other errors that will appear... Once I made the corrections above, I tried to compile and found that you haven't finished your operator++ functions. If you don't want help, then stop reading. Otherwise:
| |||
|
Last edited on
|
|||