Using C++ classes in Static lib
![Sathya Priya R](/sites/all/themes/tizen_dev_theme/images/forum/default_photo.png)
2015년 07월 24일 05:36
영어 (English)
2 댓글
Responses
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.
이 곳에 제목을 입력하세요.
All Categories
일반 지원
Tizen .NET
웹 애플리케이션 개발
Native 애플리케이션 개발
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.