English 中文(简体)
C.C++ 结构问题
原标题:C/C++ struct question
  • 时间:2011-08-20 10:57:18
  •  标签:
  • c++
  • c
  • struct

Suppose You with a .cpp file (即,汇编使用C++汇编者,如MSVC)。 在该文件中,您对<代码>struct作了如下界定:

struct Pixel
{
   float x, y;
};

在同一份档案中,你有一条称为C职能的编码线,需要一个Cstruct/code>,等于Pixel。 请写:

Pixel my_pixel
// set my_pixel to something
c_func(&my_pixel);

它会发挥作用? 我指的是,C++的汇编者将创建标的my_pixel,但将编成C代码(只有该图书馆的校准)的功能。

最佳回答

如果标题档案正确,则由C汇编者和C++汇编者使用兼容的电话公约。 保证负责人档案有适当的<代码>extern “C”栏,其中包含功能定义。

问题回答

理由David Schzwartz说,你需要一个<代码>extern “C”栏,即没有“C”栏,汇编者将“选择”你所说的C功能的名称。 如果你称之为C功能,而不是C++功能,那么贵图书馆的职能定义就没有人名,因此,你可以起诉的人将无法联系。

如果你要求履行的职能在C++中写成,那么你想要的是,因为名称拼凑使得功能名称能够超负荷。 每项功能参数的类型都以人为功能名称编码。

最初在C++中提供名称,使C++物体文档能够与遗产链接器链接,而不是提供C++-专门链接器,明确支持超负荷功能。

C. 允许功能名称超载,因此C类功能名称从未被人选。 • 在C++中为单一C功能提供原型:

extern "C" Foo( int theInt );

If you have a whole header file full of C function prototypes and you want to #include that header from a C++ source, enclose the #include in an extern C block

extern "C" {
    #include "Foo.h"
}




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签