public member friend class – error cannot be overloaded

Dear everybody, I want to define a friend class using this code:

1 #include <iostream>
2 using namespace std;
3
4 class substraction_class;
5
6 class addition_class
7 {
8 int a, b;
9 public:
10 void addition_values (int, int);
11 int addition_result ()
12 {
13 return (a+b);
14 }
15 void substraction_result (substraction_class parameter1, substraction_class parameter2);
16 } ;
17
18
19 class substraction_class
20 {
21 friend class addition_class;
22 private:
23 int c, d;
24 public:
25 substraction_class (int parameter1) : c(parameter1) {}
26 substraction_class (int parameter2) : d(parameter1) {}
27 }
28
29
30 void addition_class::substraction_result (substraction_class parameter1, substraction_class parameter2)
31 {
32 a = parameter1.c;
33 b = parameter2.d;
34 }
35
36
37
38 int main ()
39 {
40 addition_class result;
41 substraction_class result2 (3,2);
42 result.substraction_result(result2);
43 cout << "3 - 2 is: " << result.substraction_result() << "\n";
44
45 return 0;
46 }






And I am having these errors:



example1.C:26: error: ‘substraction_class::substraction_class(int)’ cannot be overloaded
example1.C:25: error: with ‘substraction_class::substraction_class(int)’
example1.C: In constructor ‘substraction_class::substraction_class(int)’:
example1.C:26: error: ‘parameter1’ was not declared in this scope
example1.C: At global scope:
example1.C:30: error: new types may not be defined in a return type
example1.C:30: note: (perhaps a semicolon is missing after the definition of ‘substraction_class’)
example1.C:30: error: two or more data types in declaration of ‘substraction_result’
example1.C: In function ‘int main()’:
example1.C:41: error: no matching function for call to ‘substraction_class::substraction_class(int, int)’
example1.C:25: note: candidates are: substraction_class::substraction_class(int)
example1.C:20: note: substraction_class::substraction_class(const substraction_class&)
example1.C:44: error: no matching function for call to ‘addition_class::substraction_result(substraction_class&)’
example1.C:15: note: candidates are: void addition_class::substraction_result(substraction_class, substraction_class)
example1.C:47: error: no matching function for call to ‘addition_class::substraction_result()’
example1.C:15: note: candidates are: void addition_class::substraction_result(substraction_class, substraction_class)
1
2
3
4
public:
    substraction_class (int parameter1) : c(parameter1) {}
    substraction_class (int parameter2) : d(parameter1) {}
}
You have Two constuctors with the same signature. This is not allowed.
Also you forgot ';' after one of your classes declaration and tried to call substraction_result() which takes two ints once with one parameter and once without parameters at all.
Topic archived. No new replies allowed.