Suppose I have a C++ library lib.h that uses classes and templates. Suppose also that I have a custom C++ header myLink.h with the following:
#include "lib.h"
//call methods from lib.h that use templates and classes
// and return an integer based off of the information gained from calling functions lib.h
extern "C" int foo(int param1, const int param2);
Now suppose I am in a C file called test.c. Is it legal to call function foo() as follows?
//in test.c
int first = foo(5, 6);
Also, what is going on at the object code / linker phase of compilation?
Thanks!
Is it legal to call function foo() as follows?
int first = foo(5, 6);
Yes, it's legal. Although you should read below to make sure this legal call will link.
what is going on at the object code / linker phase of compilation?
The use of classes won't interfere. C++ classes will be compiled to object code that the linker will understand.
Edit from Chris Dodd's comment:
Your templates will also be created by virtue of foo
calling them.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.