Using C++ classes in Static lib
由 Sathya Priya R
2015年 07月 24日 05:36
English(英语)
2 回复
响应
2 回复
pius lee
2015年 07月 27日 00:54
There is no difference public method with "extern" or not.
basically every default functions are extern function, so you don't write extern before the public method.
but if you want call some C++ function in C, use extern "C" for it.
// static_lib.h class Foobar { public: Foobar() : mValue(321) {}; int AddNumbers(int a); private: int mValue; }; // static_lib_c.h int asdf(int a); // static_lib.cc int Foobar::AddNumbers(int a) { return this->mValue + a; } static int static_a = 123; extern "C" int asdf(int a) { return static_a + a; } // static_lib_test.cc #include <static_lib.h> int main() { Foobar f; int x = f.AddNumbers(123); printf("%d", x); } // static_lib_test.c #include <stdio.h> #include <static_lib_c.h> int main() { printf("%d", asdf(321)); return 0; }
您必须登录才能使用此服务。立即登录?
The tag you entered already exists.
是否要将这篇帖子报告为垃圾邮件?
已将该帖报告为垃圾邮件。
cannot be empty.
是否确定要取消并返回列表?
The code has been copied to the clipboard.
输入标题。
所有分类
一般支持
Tizen .NET
Web 应用程序开发
本机应用程序开发
SDK 和 IDE
--------
--------
Hi,
I have added some classes with methods and built the static lib.
How do we export these class methods for use by other lib's and exe's?
Say for example, inside the static lib there is a class,
Class A{
int mValue;
public:
A();
int AddNumbers(int a){
return (this->mVaue + a);
}
};
How do we call the AddNumbers method? Where should we add the "extern" keyword ??
Thanks.