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

samy

macrumors newbie
Original poster
Sep 5, 2009
4
0
I have a class as :

Code:
@interface A
{
@private
CGFloat someVar; 
}

@property (nonatomic,readonly) CGFloat someVar; 

@end

Code:
@implementation A

@synthesize someVar;

@end

and then class B as :

Code:
@interface B
{
@private
uint someVar_In_B; 
}
@end

Code:
@implementation B

-(void)someMethod
{

// assuming someVar in 'A' is initialised to proper value say '20.0'

  CGFloat value=[pointer_to_A someVar]; // compile error --> Incompatible types in initialisation

someVar_In_B=[pointer_to_A someVar]; // works but some absurd value
}

@end


So, why would line 1 of 'someMethod' not work and line 2 work but with some absurd value.

Or, what would be the way to convert CGFloat to uint ?
 
Post compilable code that demonstrates the problem.

If you expect someone to verify the "absurd value", the posted code will have to be compiled and run, so it shows the absurd value.


When I compile the code here, targeting Mac OS 10.6, it compiles and runs fine, after I make adjustments to make it usable.

Here's my actual compilable runnable code:

Code:
#import <Foundation/Foundation.h>

@interface A [COLOR="Blue"]: NSObject[/COLOR]
{
@private
CGFloat someVar; 
}

@property (nonatomic,readonly) CGFloat someVar; 

@end


@interface B [COLOR="Blue"]: NSObject[/COLOR]
{
@private
uint someVar_In_B; 
}
@end



@implementation A

@synthesize someVar;

[COLOR="Blue"]// Added to allow setting of someVar property.
-(void)example:(CGFloat) value
{
	someVar = value;
}
[/COLOR]
@end


@implementation B

//-(void)someMethod
-(void)someMethod[COLOR="Blue"]:(A*) pointer_to_A[/COLOR]
{
	
// assuming someVar in 'A' is initialised to proper value say '20.0'

  CGFloat value=[pointer_to_A someVar]; // compile error --> Incompatible types in initialisation

someVar_In_B=[pointer_to_A someVar]; // works but some absurd value
}

@end


int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
	
	A * myA = [[A new] autorelease];
	B * myB = [[B new] autorelease];
	
	NSLog(@"someVar of A = %f", myA.someVar ); 
	NSLog(@"someVar_In_B = %i", myB->someVar_In_B ); 
	
	[myA example:20.0];
	
	[myB someMethod:myA];
	
	NSLog(@"someVar of A = %f", myA.someVar ); 
	NSLog(@"someVar_In_B = %i", myB->someVar_In_B ); 
	
		
    [pool drain];
    return 0;
}
I made only minimal changes to make it compile and run, hilited in blue.

Output:
Code:
2010-09-12 12:21:46.821 a.out[3221:903] someVar of A = 0.000000
2010-09-12 12:21:46.825 a.out[3221:903] someVar_In_B = 0
2010-09-12 12:21:46.825 a.out[3221:903] someVar of A = 20.000000
2010-09-12 12:21:46.826 a.out[3221:903] someVar_In_B = 20
 
Thanks 'chown33'.

But some how or the other now the mentioned code works.

Ofcourse there were lot of changes that went through the day.

Possibly that could be the reason.

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