|
|
Problems with Classes
|
|
|
|
Posting Junkie
Join Date: May 2001
Location: Portland, OR
Status:
Offline
|
|
I created a Obj C++ Cocoa class in Project Builder (not a subclass in IB). Now I'm trying to link it together in code. My class is called TPKG2Class.
Heres the .h file for TPKG2Class:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
<font color = brown>//</font>
<font color = brown>// TPKG2Class.h</font>
<font color = brown>// duality4</font>
<font color = brown>//</font>
<font color = brown>// Created by Colin Cornaby on Tue Jan <font color = blue>22</font> <font color = blue>2002.</font></font>
<font color = brown>// Copyright (c) <font color = blue>2001</font> Conundrum Software. All rights reserved.</font>
<font color = brown>//</font>
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import <PreferencePanes/NSPreferencePane.h>
@interface TPKG2Class : NSObject {
}
- (void)TPKG2Name;
@end
</font>[/code]
Heres the .m for TPKG2Class:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
<font color = brown>//</font>
<font color = brown>// TPKG2Class.m</font>
<font color = brown>// duality4</font>
<font color = brown>//</font>
<font color = brown>// Created by Colin Cornaby on Tue Jan <font color = blue>22</font> <font color = blue>2002.</font></font>
<font color = brown>// Copyright (c) <font color = blue>2001</font> Conundrum Software. All rights reserved.</font>
<font color = brown>//</font>
#import <font color = red>"TPKG2Class.h"</font>
@implementation TPKG2Class
- (void)TPKG2Name
{
NSLog(<font color = orange>@"hi"</font>);
}
@end
</font>[/code]
I implement it in my main class with #import "interfacecontroller.h". When I try to call "[TPKG2Class TPKG2Name];" PB gives me two warnings:
interfacecontroller.m:46: warning: cannot find class (factory) method.
interfacecontroller.m:46: warning: return type for `TPKG2Name' defaults to id
Why? As far as I can tell, everything is right... :sigh:
BTW... How do I change the default software company name for the header at the top of the code? thanks.
--Colin Cornaby
|
8 Core 2.8 ghz Mac Pro/GF8800/2 23" Cinema Displays, 3.06 ghz Macbook Pro
Once you wanted revolution, now you're the institution, how's it feel to be the man?
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Aug 2001
Location: Vienna, Austria
Status:
Offline
|
|
Is the checkbox next to the file in the project file listing checked? Otherwise it wouldn't be included in the compiled app.
Try cleaning the project and building again.
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status:
Offline
|
|
Nope, Project Builder is not the problem.
TPKG2Name is an instance method, yet in code you're calling it like a class method. The error message is correct; the compiler can not find the class method named "TPKG2Name".
If you change your declaration (and implementation) to be
+ (void)TPKG2Name;
then it will work (note the + instead of a -).
Alternatively, you could call it as an instance method:
TPKG2Class *anInstance;
anInstance = [[[TPKG2Class alloc] init] autorelease];
[anInstance TPKG2Name];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|