views:

39

answers:

1

I have a class called options written in c++, here is the header info:

class Options {
public:
string filename;
string chunkDir;
string outFilename;
string inFilename;
BOOL   compress;
BOOL   extract;
BOOL   print;
BOOL   reconstruct;
int    bits;

Options(string inFilename);
Options(int argc, char** argv);
void unsupported(string s);
void setOptionsFromArguments(int argc, char** argv);
void validateOptionCombination();
int getBits() {
    return bits
};

};

In the objective-c section, I initialize Options like this:

Options *opts=new Options([fileName cStringUsingEncoding:NSUTF8StringEncoding]);

Now what happens is that if I pass the pointer to another C++ method it works fine, but if I actually try to access anything in the objective c side using, for example

opts->bits or opts->getBits()

It always returns the integer value for print

It looks like somehow the symbol table is getting mangled between the objective-c and C++ side, but I have no idea what I could have done to do cause this.

The code works even with Objective-C++ if I compile for the mac, and as long as C++ is calling C++ it seems to work so it's not like the memory is getting corrupted, it just looks like a symbol table issue.

Any insight would be much appreciated.

+1  A: 

In Objective-C, BOOL is a typedef to signed char. What definition are you using when compiling pure C++? If it's different, you'll get all sorts of weirdness, because the C++ code and the Objective-C++ code won't agree on the size or layout of the member variables.

Derek Ledbetter
That was it, I was using unsigned short. I just changed the typedef name from BOOL to CBOOL in the C++ to avoid any potential future confusion. Thanks.