Wierd compilation problem with VC2008 but not on gcc: C linkage function cannot return C++ class

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi, all
Im tying to call some third party cpp library from my c code. The following code monics my situation here.
<div style="background-color:white; color:black
<pre><span style="color:blue template<<span style="color:blue class T>
<span style="color:blue class MyClass
{
<span style="color:blue public:
MyClass<T>(){};
};

<span style="color:blue typedef MyClass<<span style="color:blue int> MyClassD;

<span style="color:blue extern <span style="color:#a31515 "C"
{
<span style="color:blue typedef <span style="color:blue struct _ABC
{
<span style="color:green //MyClassD m_id; /* This should be added to get compiled successfully in vc2008 */
[/i] MyClassD (*getMyClass)(<span style="color:blue struct _ABC* self);
}ABC;

MyClassD abc_get_my_class(ABC* self);
};

<span style="color:blue int main()
{
<span style="color:blue return 0;
}
<br/>
[/code]

Compiling under vc2008, I got a Error 1 error C2526: abc_get_my_class : C linkage function cannot return C++ class MyClass<T>; However it got compiled successfully under gcc.
So, I add some line (which is " <span style="color:green //MyClassD m_id; /* This should be added to get compiled successfully in vc2008 */"), and get it compiled under vc2008 successfully. Anybody please tell me why? Is this
some bug for vc2008?
It will work after adding some line like that, but that would make my code ugly and nongood, any suggestions are greatly appreciated.
<br/>

View the full article
 
Back
Top