Re: Mixing ObjC and C++ STL on same ObjC source file
Re: Mixing ObjC and C++ STL on same ObjC source file
- Subject: Re: Mixing ObjC and C++ STL on same ObjC source file
- From: Daniel Luis dos Santos <email@hidden>
- Date: Fri, 12 Sep 2008 11:21:44 +0100
The problem was that in CVDisplayPipeline.h I was declaring the map as
a return type of a method, but without specifying the template types
(caused by my relative ignorance of C++).
Now I have another problem, which I wonder if you could help :
On one project I have a target that builds a shared library target in C
++ exclusively. On another target I have a objC app that uses the
first as a project dependency.
When I call a method on the library with a pointer to a STL map
(std::map<std::string, std::string>) as an argument, the linker
complains it can't find it. I made a test method on the lib that takes
only a std::string and it works. Passing a std::map<int, int> fails
with the same error. Other methods in the lib that don't use STL are
found by the linker.
Don't know what is happening, or if there is any limitation because of
STL.
On Sep 12, 2008, at 9:29 AM, email@hidden wrote:
On 12 Sep 2008, at 10:17, Daniel Luis dos Santos wrote:
Hello !
I have an objective C class and want to call a method on a class in
C++. As argument to the C++ class is a map instance of the STL.
The ObjC class definition is on a file with a mm extension.
I have std::map *var as a member variable of the ObjC class. When I
compile the code there is an error saying :
/Users/dlsa/code/Finema/trunk/LiquidSurfaces/src/
CVDisplayPipeline.h:20: error: using-declaration for non-member at
class scope
How do I do this ?
_______________________________________________
Does this happen when you compile CVDisplayPipeline.mm, or when you
compile another file which might only be a .m file? If it is the
latter, then that would be your problem since you are no longer
compiling Obj-C++.
If it is in CVDisplayPipeline.mm then It could just be that you
aren't including the right header file in CVDisplayPipeline.h (<map>
I think).
If you do have to include your .h file in other .m files, you can
workaround the problem of having pointers to C++ classes like so:
#if defined(__cplusplus)
#include <map>
typedef std::map* std_mapPtr;
#else
typedef void* std_mapPtr;
#endif
@interface MyClass: NSObject
{
std_mapPtr mMap;
}
-(std_mapPtr) map;
-(void) setMap: (std_mapPtr) aMap;
@end;
Matt
_______________________________________________
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