Problem with friend function and gcc 4.2 with objective-c++
Problem with friend function and gcc 4.2 with objective-c++
- Subject: Problem with friend function and gcc 4.2 with objective-c++
- From: Ken Worley <email@hidden>
- Date: Thu, 7 Aug 2008 16:09:29 -0600
Hi all,
I'm using Xcode 3.1 and just switched to gcc 4.2 from 4.0, but I've
run into a problem with friend functions when compiling in objective-c+
+. I contrived an example that illustrates the problem:
1. Created new Cocoa project
2. Forced compilation of all files to use objective-c++
3. Changed content of main.m to below...
This project builds fine using gcc 4.0, but when I switch the compiler
setting to use gcc 4.2, I get the errors listed below. Any clues would
certainly be appreciated if I'm doing something wrong. If not, I guess
I'll file a bug...
Here's main.m:
#import <Cocoa/Cocoa.h>
class test1
{
public:
friend test1* newtest1(int x)
{
test1* anobj = new test1();
anobj->finishinit(x);
return anobj;
}
virtual ~test1()
{
}
private:
int avalue;
test1()
{
avalue = 0;
}
void finishinit(int x)
{
avalue = x;
}
};
int main(int argc, char *argv[])
{
test1* tobj = newtest1(5);
delete tobj;
return NSApplicationMain(argc, (const char **) argv);
}
Here's the build log:
Building target “Untitled” of project “Untitled” with configuration
“Debug” — (1 error)
cd /Users/ken/Desktop/Untitled
/Xcode3.1/Developer/usr/bin/gcc-4.2 -x objective-c++ -arch i386 -
fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -fasm-blocks -
O0 -Wreturn-type -Wunused-variable -isysroot /Xcode3.1/Developer/SDKs/
MacOSX10.5.sdk -mfix-and-continue -fvisibility-inlines-hidden -mmacosx-
version-min=10.5 -gdwarf-2 -iquote /Users/ken/Desktop/Untitled/build/
Untitled.build/Debug/Untitled.build/Untitled-generated-files.hmap -I/
Users/ken/Desktop/Untitled/build/Untitled.build/Debug/Untitled.build/
Untitled-own-target-headers.hmap -I/Users/ken/Desktop/Untitled/build/
Untitled.build/Debug/Untitled.build/Untitled-all-target-headers.hmap -
iquote /Users/ken/Desktop/Untitled/build/Untitled.build/Debug/
Untitled.build/Untitled-project-headers.hmap -F/Users/ken/Desktop/
Untitled/build/Debug -I/Users/ken/Desktop/Untitled/build/Debug/include
-I/Users/ken/Desktop/Untitled/build/Untitled.build/Debug/
Untitled.build/DerivedSources -include /var/folders/JE/
JEJ3RSLHE9uIDGjXTRTis++++TI/-Caches-/com.apple.Xcode.501/
SharedPrecompiledHeaders/Untitled_Prefix-brblicjbwwpqhfahflncgqpvarno/
Untitled_Prefix.pch -c /Users/ken/Desktop/Untitled/main.m -o /Users/
ken/Desktop/Untitled/build/Untitled.build/Debug/Untitled.build/Objects-
normal/i386/main.o
/Users/ken/Desktop/Untitled/main.m: In function 'int main(int, char**)':
/Users/ken/Desktop/Untitled/main.m:43: error: 'newtest1' was not
declared in this scope
/Users/ken/Desktop/Untitled/main.m:43: error: 'newtest1' was not
declared in this scope
Build failed (1 error)
Thanks,
Ken
--
Ken Worley
Software Engineer, Tiberius, Inc.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden