Using C++ classes in Static lib
![Sathya Priya R](/sites/all/themes/tizen_dev_theme/images/forum/default_photo.png)
24 Jul 2015 05:36
English
2 Replies
Responses
2 Replies
pius lee
27 Jul 2015 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; }
- Log in to post comments
Sathya Priya R
pius lee
27 Jul 2015 01:26
Thank you!
- Log in to post comments
You must log in to use this service. Log in now?
The tag you entered already exists.
Do you want to report this post as spam?
The post has been reported as spam.
cannot be empty.
Are you sure you want to cancel and return to the list?
The code has been copied to the clipboard.
Enter a title.
All Categories
General Support
Tizen .NET
Web Application Development
Native Application Development
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.