Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top