Using a function that is defined in another Class

How can I use a function that is defined in another class, for example I want to use a funcion that is defined in a class, from the main() function ?
Create an object of that class type. Call the function.

For example,
1
2
string someObject; // Create object of type string
someObject.size(); // Call the string function "size" 
closed account (zb0S216C)
You mean this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Object
{
    public:
        // ...

    void Function(void)
    {
        //...
    }
};

int main(void)
{
    ::Object New_obj;
    New_obj.Function();
    return(0);
}


Edit: Ninja'd by Moschops :)

Wazzak
Last edited on
You don't really need the two colons before Object.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Object
{
	public:
	//...
	void Function(void)
	{
		//...
	}
};
int main(void)
{
	Object New_obj;
	New_obj.Function();
	return 0;
}
closed account (zb0S216C)
Taran Gadal: I know, I just like to be explicit about where a type is situated.

Wazzak
Thank you both guys!
What I love about this forum is the "speed of light answers" lol :D
Very good! :)
Topic archived. No new replies allowed.