简体   繁体   中英

Casting C++ types with ARC in objective-c

Stumbled with the following situation:

I work with a 3-rd party C++ library.

lib's header:

#define lib_fname               char 
typedef lib_fname*              lib_l_fname;

Function(lib_l_fname name);

my code(I need to call that func):

Function ((lib_l_fname)[@"name" UTF8String]);

This worked in not-ARC project, but in with ARC i have an error - "Cast of an Objective-C pointer to lib_l_fname (aka char*) is disallowed with ARC"

I tried

  Function ([@"name" UTF8String]);

But it didn't work. Is there a solution?

Found a solution:

Compiling with arc is more strict and it gives errors when trying to cast const char* to char*.

The solution was to create a second string char* and to strcpy there [@"name" UTF8String]

 char str2[1024] = {0};
 strcpy(str2, [@"name" UTF8String]);

 Function ((lib_l_fname)str2);

works as expected

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM