Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ncohen

macrumors newbie
Original poster
Mar 31, 2009
8
0
Hi everybody,
In my main I create an object recorder and I call one of its method... in this method I would like to call a method of my main... is it possible? How can I do that?

Thanks
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
When you say "call a method of my main", do you mean call a function that is defined in the same source file as your main function, or do you mean invoke main?

It seems somewhat strange to me, but you can call main like any other function. If you need to pass arguments you should do so via argc and argv, allocating a char ** of the appropriate size, then a char * for each argument. Again, this seems unusual and i would try to figure out a different design if possible.

-Lee
 

ncohen

macrumors newbie
Original poster
Mar 31, 2009
8
0
sorry it wasn't clear...
my main is a class (it's my MainView for iphone). In this class I create an object and call a function of this object (recorder)! In this object I need to call a function which belongs to MainView.

Hope it's clearer now :)
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
oh, this makes a bit more sense. In the constructor or a setter for the "recorder" you should accept an object * of the type of MainView, and declare an instance variable of this type. When you instantiate the "recorder" object in a method in your MainView object, you would pass the variable "self" as this argument. In the "recorder" class you would store the pointer to the MainView object, and when needed, you would pass a message to this object to invoke a method.

It's somewhat circular and hard to follow, but hopefully that's clear enough to get you where you need to go.

-Lee
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.