class function calling a function from another class

int main () {
calls class1::test
}

class 1 {
public:
void test();
}

void test() {
calls class 2::test2
}


class2{
public: test2()
}

void test2() {
cout << "MAIN CALLED CLASS 1 AND CLASS 1 CALLED CLASS 2 AND THIS MESSAGE WAS DISPLAYED";
}

can someone please explain to me how this works and give me some example code (something like above but works in compiler) of how a simple cout message can be called by the main calling a class and that class calling another class?
thanks.
Last edited on
It doesn't work.
Also, it seems you don't understand what a class is (or at least what "calling" means). A class is just a type. You can't call a class just as much as you can't call an int. You can only call functions.
Now, here's an example that does work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

class A{
	static void f(){
		std::cout <<"A::f()"<<std::endl;
	}
};

class B{
	static void f(){
		A::f();
	}
};

int main(){
	B::f();
	return 0;
}
thank you very very very VERY much! i understand it now thanks!!
back to finishing my assignment now that i understand this :) ty again!
Hello.well,i'm a new forumer.i'm still new to the C++ programming and already got assignments that i could'nt think how to do it.So,i really hope that some of you can help me to do this assignments.Hopefully,i can solve this assignments as soon as possible.Below are the questions:

1.Write a program with function prototype that asks the user to input
-The number of gallons of gas in the tank.
-The fuel efficiency in miles per gallon
-The price of gas per gallon.

Then print the cost per 110 miles and how far the car can go with the gas in the tank.

hint:

1st function-user input
2nd function-calculation
3rd function-display


2.Write a program that can do the following tasks,with no specified input.

a.Read floating number and print the largest value.
b.Read floating number and print the smallest value.
c.Read floating number and print.
d.Read floating number and print the average number.

hint:use function for each task.


Really hope for your help.Thank you.
Topic archived. No new replies allowed.