0

I saw a similar question involving using opaque types, but I don't quite understand the sample code.

I've got some code which works...where I have several C++ data objects stored as instance variables in my controller. I'd like to conform to MVC, and get all of this pushed down into a model object, and not my controller.

So what I have now that works looks like:

@interface WinController : NSWindowController <NSWindowDelegate>
{
    cv::Mat object;
}
- (void)setObject:(const cv::Mat&)newObject;
@end

@implementation

- (void)setObject:(const cv::Mat&)newObject
{
    object = newObject;
}
@end

And this setObject: method is called by a different class's method:

- (void)constructObject
{
    cv::Mat object = cv::Mat::zeros(3,3,CV_64F);
    [myController setObject:object];
}

So I move the C++ object out of the controller and into a model class. The @interface and @implementation is exactly the same. Just copied and pasted into a different class.

The constructObject: method changes to this:

- (void)constructObject
{
    cv::Mat object = cv::Mat::zeros(3,3,CV_64F);
    [myController.myModel setObject:object];
}

Now when I compile, I get a new warning: Instance method '-setObject:' not found. (return type defaults to 'id')

So clearly I'm missing some subtlety on why method #1 works, and #2 doesn't.

Community
  • 1
  • 1
wrjohns
  • 484
  • 4
  • 14
  • The "subtlety" is almost certainly a typo or silly mistake in code you haven't posted. – pmdj Aug 04 '12 at 16:04
  • Have you imported the .h file of the new model code from the file with the constructObject method? – André Pareis Aug 05 '12 at 10:39
  • I had. And when I got the warning, I assumed there was an actual problem that the code would choke on at run time. I tried running it, and it worked just fine. I did eventually eliminate the error, by rearranging the order I imported the header files. Yuck. – wrjohns Aug 05 '12 at 15:23

0 Answers0