tags:

views:

574

answers:

7
A: 

It may not be feasible in your case, but I've seen people employ a little preprocessor-foo to massage the types into compatibility.

Even this assumes that you are building one or both libraries.

It is also possible that you don't want to do this at all, but want to re-evaulate some early decision. Or not.

Good luck.

dmckee
A: 

If the structs were the same internally, you could do a reinterpret_cast; however, since it looks like you have 16-bit vs 32-bit fields, you're probably stuck converting on each call, or writing wrappers for all functions of one of the libraries.

Stu
A: 
mmattax
A: 

Maybe you could try it with operator overloading ? (Maybe a = operator which is not a method of your class) ?

Rect operator= (const Rect&,const rectangle&)

More about this in the C++ programming language by Bjarne Stroustrup or maybe on this page: http://www.cs.caltech.edu/courses/cs11/material/cpp/donnie/cpp-ops.html

bernhardrusch
It is not legal in C++ to define operator= outside a class.
alexk7
+4  A: 

Create an intermediate shim type "RectangleEx", and define custom conversions to/from the 3rd-party string types. Whenever you speak to either API, do so through the shim class.

Another way would be to derive a class from either rect or Rectangle, and insert conversions/constructors there.

James D
+1  A: 

If you can't modify the structures then you have no alternative to writing a manual conversion function because overloading conversion operators only works within the class body. There's no other way.

Konrad Rudolph
+3  A: 

Not sure how sensible this is, but how about something like this:

class R
{
public:
    R(const rectangle& r) { ... };
    R(const Rect& r) { ... };

    operator rectangle() const { return ...; }
    operator Rect() const { return ...; }

private:
    ...
};

Then you can just wrap every rectangle in R() and the "right thing" will happen.

Kristopher Johnson