i**p 发帖数: 902 | 1 I know C code can call member methods in the C++ library by using "extern C"
. Is it possible to call Class's constructor? How? |
l********a 发帖数: 1154 | 2 re-write the 'class' as struct |
b***i 发帖数: 3043 | 3 你这个目的是什么?
【在 l********a 的大作中提到】 : re-write the 'class' as struct
|
i**p 发帖数: 902 | 4 No 目的. Just curious how to do it.
【在 b***i 的大作中提到】 : 你这个目的是什么?
|
i**p 发帖数: 902 | 5 Yes, C can access the member variable by the struct, but how can it call the
constructor? Could you show an example if you know?
【在 l********a 的大作中提到】 : re-write the 'class' as struct
|
c*******y 发帖数: 1630 | 6 there is no ctor in c, even you managed to call it, it will be undefined
behavior. not to mention, if there is virtual function in that class.
http://stackoverflow.com/questions/537244/constructor-in-c
use wrapper if you really want to try, but it's pointless.
the
【在 i**p 的大作中提到】 : Yes, C can access the member variable by the struct, but how can it call the : constructor? Could you show an example if you know?
|
b***i 发帖数: 3043 | 7 你一定要说目的,不同 目的有不同答案。如果你想要一个对象的指针,可以做到,如
果你想完成ctor里面做的事情,可以做到,如果你就是想直接呼叫ctor,不可能。
C只能呼叫C++库里面的extern "C" 修饰过的函数。这样的函数里面做你要做的事情。
【在 i**p 的大作中提到】 : No 目的. Just curious how to do it.
|
i**p 发帖数: 902 | 8 我的目的就是想知道能不能用extern "C" 或其它方法修饰ctor, 然后用C呼叫.
【在 b***i 的大作中提到】 : 你一定要说目的,不同 目的有不同答案。如果你想要一个对象的指针,可以做到,如 : 果你想完成ctor里面做的事情,可以做到,如果你就是想直接呼叫ctor,不可能。 : C只能呼叫C++库里面的extern "C" 修饰过的函数。这样的函数里面做你要做的事情。
|
p***o 发帖数: 1252 | 9 extern "C" void default_ctor_of_A(A *p) {new (p) A;}
【在 i**p 的大作中提到】 : 我的目的就是想知道能不能用extern "C" 或其它方法修饰ctor, 然后用C呼叫.
|
t****t 发帖数: 6806 | 10 不能.
【在 i**p 的大作中提到】 : 我的目的就是想知道能不能用extern "C" 或其它方法修饰ctor, 然后用C呼叫.
|