在这个程序中,我有一个void *参数,并希望将其转换为特定类型.但我不知道使用哪种"铸造符号".无论是static_cast还是reinterpret_cast工作.哪一个更好?标准C++推荐哪一个?
typedef struct
{
int a;
}A, *PA;
int foo(void* a) // the real type of a is A*
{
A* pA = static_cast<A*>(a); // or A* pA = reinterpret_cast<A*>(a);?
return pA->a;
}
Run Code Online (Sandbox Code Playgroud)
这是
A* pA = static_cast<A*>(a);
Run Code Online (Sandbox Code Playgroud)
要么
A* pA = reinterpret_cast<A*>(a);
Run Code Online (Sandbox Code Playgroud)
更合适吗?
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int i1 = 0;
int i2 = 10;
const int *p = &i1;
int const *p2 = &i1;
const int const *p3 = &i1;
p = &i2;
p2 = &i2;
p3 = &i2;
cout << *p << endl
<< *p2 <<endl
<< *p3 <<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
可以使用VC6.0和VC2010编译代码.但我有一个问题:
const int*p =&i1;
这意味着什么"p"点不能修改,但p不能修改,我是对的吗?所以
p =&i2;
这条线可以遵守,是吗?
这一行:
int const *p2 = &i1;
Run Code Online (Sandbox Code Playgroud)
在我看来,这意味着p2无法修改,而p2点可以改变,我是对的吗?为什么
p2 =&i2;
可以编译?
关于这一行:
const int const*p3 …
我想查看“.ocx”文件的接口。像这样:

但对于某些 .ocx,我只能看到 5 个函数,如下所示:

问题是:如何才能看到这些ocx文件的接口。我已经尝试过这个:
A.a
) 我想注册它并在 Visual Studio 中查看它。但是当我注册它时,出现错误“LoadLibrary(path:\filename.ocx) failed”。像这样:

b) 然后我用“Dependency Walker”打开ocx,发现文件依赖没有DLL文件。

c) 如何注册?
B. 我使用“Dll Export Viewer”,现在我可以看到函数的名称,但仍然无法获取函数的参数。如何获取函数的参数?
我尝试在Xcode 4.2中运行代码:
int main(int argc, const char * argv[])
{
locale loc("chs");
locale::global(loc);
wstring text(L"??");
wcout << text << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我收到错误"Thread 1:signal SIGABRT".
你能告诉我为什么会发生错误,或者如何使用wstring和wcout输出中文单词?
#include <vector>
using std::vector;
class A
{
public:
A()
{
buf.push_back(65);
buf.push_back(66);
buf.push_back(67);
}
~A(){}
const char * getA() const
{
// why never run here?
return &buf[0];
}
const char * getA()
{
return &buf[0];
}
char * getB() const
{
// why compile error?
return &buf[0];
}
char * getB()
{
return &buf[0];
}
private:
vector<char> buf;
};
int main()
{
A a;
const char * pc = a.getA();
const char * const cp = a.getA();
char * …Run Code Online (Sandbox Code Playgroud)