我正在尝试显式链接 DLL。除了 DLL 文件本身以及有关类及其成员函数的一些文档之外,没有其他资源可用。
从文档来看,每个类都有自己的
typedef std::map<std::string,std::string> Server::KeyValueMap, typedef std::vector<std::string> Server::String Arrayenum Server::Role {NONE,HIGH,LOW}void Server::connect(const StringArray,const KeyValueMap), void Server::disconnect()实现来自谷歌搜索的代码,我设法加载可以调用断开连接函数的dll。
目录.h
LPCSTR disconnect = "_Java_mas_com_oa_rollings_as_apiJNI_Server_1disconnect@20";
LPCSTR connect =
"_Java_mas_com_oa_rollings_as_apiJNI_Server_1connect@20";
Run Code Online (Sandbox Code Playgroud)
我从depends.exe 中获取了上面的函数名称。这就是 C++ 中所谓的修饰/修饰函数名称吗?
主程序
#include <iostream>
#include <windows.h>
#include <tchar.h>
#include "dir.h"
typedef void (*pdisconnect)();
int main()
{
HMODULE DLL = LoadLibrary(_T("server.dll"));
pdisconnect _pdisconnect;`
if(DLL)
{
std::cout<< "DLL loaded!" << std::endl;
_disconnect = (pdisconnect)GetProcAddress(DLL,disconnect);
if(_disconnect)
{
std::cout << "Successful link to …Run Code Online (Sandbox Code Playgroud) 以下内容在 Visual C++ 2015 Update 2 上运行良好。请注意,它A是不可复制的,并且A::A是explicit.
#include <iostream>\n#include <tuple>\n\nstruct A\n{\n explicit A(int i)\n {\n std::cout << i << " ";\n }\n\n // non-copyable\n A(const A&) = delete;\n A& operator=(const A&) = delete;\n};\n\n\ntemplate <class... Ts>\nstruct B\n{\n std::tuple<Ts...> ts;\n\n B(int i)\n : ts((sizeof(Ts), i)...)\n {\n }\n};\n\n\nint main()\n{\n B<A, A, A, A> b(42);\n}\nRun Code Online (Sandbox Code Playgroud)\n\n目标是将相同的参数传递给所有元组元素。它正确输出:
\n\n42 42 42 42\nRun Code Online (Sandbox Code Playgroud)\n\n但是,它无法在 g++ 4.9.2 上编译。在众多消息中,tuple我认为应该调用构造函数重载:
In instantiation of \xe2\x80\x98B<Ts>::B(int) [with Ts = …Run Code Online (Sandbox Code Playgroud) 我的应用需要有一个intent-filter响应Intent具有它的组件集(一个明确的意图).这是一个例子.
Intent i = new Intent();
i.setClassName("com.compareeverywhere","com.compareeverywhere.ScanActivity");
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
只是一个简单的intent-filter不会做 - 因为它Intent是针对特定组件(Activity,),它只是启动,而不是寻找意图.有没有办法做到这一点?
谢谢,Isaac Waller
PS:请不要回答"不".
请考虑以下代码:
#include<iostream>
#include<utility>
struct Base
{
int baseint;
};
struct Der1 : Base
{
int der1int;
Der1() : der1int(1) {}
explicit Der1(const Base& a) : Base(a), der1int(1)
{
std::cerr << "cc1" << std::endl;
}
};
struct Der2 : Base
{
int der2int;
Der2() : der2int(2) {}
explicit Der2(const Base& a) : Base(a), der2int(2)
{
std::cerr << "cc2" << std::endl;
}
};
template <typename T, typename U>
struct MyPair
{
T first;
U second;
};
int main()
{
Der1 d1;
Der2 …Run Code Online (Sandbox Code Playgroud) 我有一个有2个构造函数的类.
explicit MyClass(size_t num);
template<class T> MyClass(T myObj);
Run Code Online (Sandbox Code Playgroud)
每当我做的时候我都想要
MyClass obj( 30 );
Run Code Online (Sandbox Code Playgroud)
将调用第一个构造函数,
在隐式构造函数和
MyClass obj = 30;
Run Code Online (Sandbox Code Playgroud)
第二个ctor将被召唤.
我怎样才能实现呢?
我试图将c#代码转换为c ++/cli.一切顺利,直到我开始将接口事件显式实现转换为c ++/cli语法.
让我们说在c#我有这个界面
public interface Interface
{
public event MyEventHandler Event;
}
Run Code Online (Sandbox Code Playgroud)
这是以明确的方式在Class中实现的,因此它不会通过其名称与另一个成员冲突:
public interface Class : Interface
{
event MyEventHandler Interface.Event;
public event AnotherEventHandler Event;
}
Run Code Online (Sandbox Code Playgroud)
我试图将Class转换为c ++/cli,如下所示:
public ref class Class : public Interface
{
virtual event MyEventHandler^ Event2 = Interface::Event
{
}
...
};
Run Code Online (Sandbox Code Playgroud)
这将无法编译,在"... = Interface :: Event"部分给出了语法错误.有没有人知道什么是正确的语法,或者它甚至存在于c ++/cli中?我花了一些时间在互联网上搜索,但未能碰到任何有用的东西.
更新:这是完整的c ++/cli代码,用于演示此问题:
public delegate void MyEventHandle();
public delegate void AnotherEventHandle();
public interface class Interface
{
event MyEventHandler^ Event;
};
public ref class Class : public Interface …Run Code Online (Sandbox Code Playgroud) 如果项目包含Form类,则表单可以通过以下方式显示:
Form1.Show
Run Code Online (Sandbox Code Playgroud)
或者是否需要首先创建表单的实例?
Dim frm As New Form1
frm.Show
Run Code Online (Sandbox Code Playgroud) 如何检查某些类型是否可以从其他类型显式(或反之,隐式)构造?在这种情况下,这是SFINAE的伎俩吗?
我可以写is_explicitly_constructible一个的组合std::is_constructible和std::is_convertible:
#include <type_traits>
template <typename Type, typename Argument>
struct is_explicitly_constructible
: std::bool_constant
<
std::is_constructible<Type, Argument>::value &&
!std::is_convertible<Argument, Type>::value
>
{
};
Run Code Online (Sandbox Code Playgroud)
但是,我是否考虑了此类代码中的所有可能情况?
第一次尝试,一切正常:
class Base {
public:
Base() {std::cout << "default ctor!\n"; }
};
...
Base b{};
Base b_one = {};
Run Code Online (Sandbox Code Playgroud)
另一种实现方式(添加explicit):
class Base {
public:
explicit Base() {std::cout << "default ctor!\n"; }
};
...
Base b{};
Base b_one = {}; // error! Why?
Run Code Online (Sandbox Code Playgroud)
我已经读过cppreference,在这两种情况下都会使用默认初始化而不会出现diffences.
从列表初始化:
否则,如果braced-init-list为空且T是具有默认构造函数的类类型,则执行值初始化.
从值初始化:
如果T是没有默认构造函数的类类型,或者是用户提供或删除的默认构造函数,则该对象是默认初始化的;
我在openSUSE Leap 15上使用Qt 5.9.4上的GCC7.
我有以下课程:
class ManSuppProps : public QObject
{
Q_OBJECT
public:
explicit ManSuppProps(QString parentName);
explicit ManSuppProps(){}
explicit ManSuppProps(const ManSuppProps &manSuppProps);
explicit ManSuppProps(ManSuppProps &manSuppProps);
~ManSuppProps();
private:
QVector3D m_suppPos;
QString m_suppParentName;
}
Run Code Online (Sandbox Code Playgroud)
通过以下构造函数的实现:
ManSuppProps::ManSuppProps(QString parentName)
: QObject()
, m_suppPos(QVector3D(0, 0, 0))
, m_suppParentName(parentName)
{
qDebug()<<"Constructing ManSuppProps object ...";
}
ManSuppProps::ManSuppProps(const ManSuppProps &manSuppProps)
: QObject()
, m_suppPos(manSuppProps.getSuppPos())
, m_suppParentName(manSuppProps.getSuppParentName())
{
}
ManSuppProps::ManSuppProps(ManSuppProps &manSuppProps)
: QObject()
, m_suppPos(manSuppProps.getSuppPos())
, m_suppParentName(manSuppProps.getSuppParentName())
{
}
ManSuppProps::~ManSuppProps(){}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
错误:没有匹配函数来调用'ManSuppProps :: ManSuppProps(ManSuppProps&)'
在具有类成员的另一个类的方法中ManSuppProps:
ManSuppProps EditorScene::manSuppProps() …Run Code Online (Sandbox Code Playgroud)