Amazon.com Widgets Error when try to use the dealloc inside Rectangle
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 19, 2013, 05:17:10 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Program Examples
| | |-+  Chapter 8
| | | |-+  Error when try to use the dealloc inside Rectangle
Pages: [1]   Go Down
Print
Author Topic: Error when try to use the dealloc inside Rectangle  (Read 1229 times)
Charras
Newbie
*
Posts: 1


Email




« on: September 26, 2009, 11:19:28 PM »

Hello;

I'm having the following problem:

-(id) dealloc
{
   [origin release];
   return [super dealloc];
        x error: void value not ignored as it ought be
}
! warning: control reaches end of non-void function


But if I just change the (id) to (void), the program works just fine, likes follow:

-(void) dealloc
{
        [origin release];
        [super dealloc];
}
 
Like this, the program doesn't give me any problems, but I want to understand what it's happening. By the way, other problem that I have with this same program (8.5) is that if I type:

myRect.origin = myPoint;

The program give me the following error: request for member 'origin' in something not a structure or union
But if I just change it to:

[myRect setOrigin: myPoint];

The program works perfect.

Regards!
Logged
skochan
Administrator
Hero Member
*****
Posts: 3103







« Reply #1 on: September 27, 2009, 11:59:28 AM »

dealloc does not return a value, and should be declared as a void method if you override it.  In the second case, I'm guessing that myRect is declared as type id.   You can't use the dot operator with an id variable (although I've never seen Apple state that, the compiler won't accept it).

Cheers,

Steve Kochan
Logged
ozmotion
Newbie
*
Posts: 3






« Reply #2 on: January 26, 2010, 01:51:55 PM »

For the reference of those using the 1st/2nd printing who experience the same 'void value not ignored' problem, this is corrected in the 1st/2nd printing errata master list http://classroomm.com/objective-c/index.php?topic=18.0. 'dealloc' is defined in NSObject.h to return void, not id, and the code examples were updated to reflect this in later printings.

As for Charras's second question, I had trouble duplicating the problem. For both versions of setOrigin (the 1st simply copied a pointer; the 2nd created a new XYPoint object and copied the x and y values), I was able to use the dot operator successfully.
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.