由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C calls C++ library
相关主题
What does the default constructor do?[合集] C++的弱问题
c++ initialize struct急问:compile and build dependency
c++ questionfind bugs of c++ codes
问个题。C++ question
C++ 中 myobject * a =new myobject[n] 的问题问一个 copy constructor 的问题 (C++)
一道c++的考古题const object
不明白C++的一个地方C++ 问题
回答C++的弱问题C++的一个小疑问,求解惑
相关话题的讨论汇总
话题: c++话题: library话题: call话题: class话题: extern
进入Programming版参与讨论
1 (共1页)
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呼叫.
1 (共1页)
进入Programming版参与讨论
相关主题
C++的一个小疑问,求解惑C++ 中 myobject * a =new myobject[n] 的问题
问个copy constructor的问题一道c++的考古题
one question about struct不明白C++的一个地方
[合集] C++ interview question help回答C++的弱问题
What does the default constructor do?[合集] C++的弱问题
c++ initialize struct急问:compile and build dependency
c++ questionfind bugs of c++ codes
问个题。C++ question
相关话题的讨论汇总
话题: c++话题: library话题: call话题: class话题: extern