有人可以告诉我如何从.cpp和.hpp文件创建静态库吗?我需要创建.o和.a吗?我还想知道如何编译静态库并在其他.cpp代码中使用它.我有header.cpp,header.hpp .我想创造header.a.测试header.a in test.cpp.我正在使用g ++进行编译.
HI.
如何在.h文件中定义bool方法并在cpp文件中使用它?我有
my.h
#include <string>
public class me;
class me
{
public:
me();
private bool method(string name); //it is ok??
}
Run Code Online (Sandbox Code Playgroud)
my.cpp
#include 'my.h';
me::me()
{
method(string name); //can i do this? isn't there another alternative?
}
method (String name)
{
cout<<"name"<<endl;
}
Run Code Online (Sandbox Code Playgroud)
不工作.为什么?
有人可以告诉我创建包含类,子类和方法的.hpp和.cpp的正确方法是什么?我必须使用export "C" firstClass* create_object { return new firstClass; }吗?(我使用C ++工作。)我应该拥有file.hpp还是file.h?
#include <string>
//public ?? how can i have this?
class firstClass
{
public:
firstClass();
class secondClass
{
public:
secondClass();
std::string name;
virtual std::string method1();
} *sec;
virtual void DoSomething();
} *first;
// And for a private class?
class private *priv;
Run Code Online (Sandbox Code Playgroud)
在file.cpp中
#include file.hpp
firstClass::firstClass()
{
sec = new firstClass::secondClass();
}
std::string firstClass::secondClass::method1()
{
//code
}
Run Code Online (Sandbox Code Playgroud)
现在是否extern每个类/子类都必须有一个对象?如果要创建一个.so文件并使用dlsym和dlopen来访问类,子类和方法,修改值,发送对特定方法的引用,是否有必要?谢谢!
extern "C" firstClass* create_object()
{return new …Run Code Online (Sandbox Code Playgroud)