passing messages between objects ?

if you have a class named College which has a method "void getFees(double)", and another class named Student which have a method "double payFees()" and you wrote this code in the main for example:
College c();
Student s();
c.getFees(s.payFees());
is this a correct example of passing messages between objects ?
The short answer is yes but it's a good idea to always try and write some code to check it for yourself, such as:

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
#include<iostream>
using namespace std;

class College{
	private:
	
	public:
		void getFees(double d);
};
class Student{
	private:
		
	public:
		double payFees();
};
int main(){
	College c;
	Student s;
	c.getFees(s.payFees());
}
void College::getFees(double d){
	cout<<"Fees are: "<<d<<endl;
}
double Student::payFees(){
	double Fees;
	cout<<"Enter fees: "<<endl;
	cin>>Fees;
	return Fees;
}

One thing to bear in mind is that payFees() returns a local variable and so you cannot return an reference in this case
Topic archived. No new replies allowed.