我有这个C代码(灵感来自测试)
#include <stdio.h>
int foo (int n)
{
static int s = 0;
return s += n;
}
int main()
{
int y;
int i;
for (i=0; i<5; i++) {
y= foo(i);
}
printf("%d\n", foo);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我特别感兴趣的是它的价值foo
和类型.编译器给了我这个警告
test.c:18:16: warning: format specifies type 'int' but the argument has type
'int (*)(int)' [-Wformat]
Run Code Online (Sandbox Code Playgroud)
但我不确定这意味着什么.什么是int (*)(int)
如何调用没有参数的函数名称给我这种类型的东西?
以下示例出错,因为X
使用了undefinedstruct T
struct T;
struct X {
X() { }
T x;
};
struct T
{
T() { w = new X(); }
X *w;
};
int main() { }
Run Code Online (Sandbox Code Playgroud)
我可以解决这个问题的一种方法是使用指针成员struct X
而不是完整类型T *x
.有没有任何棘手的方法来解决这个问题而不改变代码中的任何类型?
是否可以使用const_iterator迭代直到main()函数中的列表结尾?我尝试使用iter-> end()但我无法弄明白.
#include <list>
#include <string>
using std::list;
using std::string;
class list_return
{
public:
list <string>::const_iterator get_list()
{
_list.push_back("1");
_list.push_back("2");
_list.push_back("3");
return _list.begin();
}
private:
list <string> _list;
};
int main()
{
list_return lr;
list <string>::const_iterator iter = lr.get_list();
//here, increment the iterator until end of list
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我最后这样做了,
struct init
{
CHAR Name[65];
};
void main()
{
init i;
char* _Name = "Name";
int _int = 0;
while (_Name[_int] != NULL)
{
i.Name[_int] = _Name[_int];
_int++;
}
}
Run Code Online (Sandbox Code Playgroud) 我想在显示控制台窗口之前创建一个像窗口一样的对话框.我还没有尝试任何东西,但只是想知道它是否可以显示为启动窗口.
你能在std :: set中获得最后一个或新添加的元素吗?例如,如果循环运行以收集元素以填充std :: set.
如果第一次运行该集合,
[0] "A"
[1] "B"
[2] "D"
Run Code Online (Sandbox Code Playgroud)
并且,在第二次运行时,该集合变为
[0] "A"
[1] "B"
[2] "C"
[3] "D"
Run Code Online (Sandbox Code Playgroud)
你如何检查'C'是否是添加的新元素?
为什么我没有分配或添加任何元素列表下面的内存泄漏错误.我应该忽略它吗?
#define CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#include <list>
using std::list;
int main()
{
list <char*> roots;
_CrtDumpMemoryLeaks();
}
Run Code Online (Sandbox Code Playgroud) 我无法让它正常工作.
#include <windows.h>
int main()
{
DWORD i = 6521;
BYTE first = i >> 32;
BYTE second = i >> 24;
BYTE third = i >> 16;
BYTE fourth = i >> 8;
i = (((DWORD)fourth) << 24) | (((DWORD)third) << 16) | (((DWORD)second) << 8) | first;
}
Run Code Online (Sandbox Code Playgroud) 什么时候需要在多线程应用程序中使用这种类型的修改消息循环?
DWORD nWaitCount;
HANDLE hWaitArray[4];
BOOL quit;
int exitCode;
while (!quit)
{
MSG msg;
int rc;
rc = MsgWaitForMultipleObjects(nWaitCount, hWaitArray, FALSE, INFINITE,QS_ALLINPUT);
if (rc == WAIT_OBJECT_O + nWaitCount)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
quit = TRUE;
exitCode = msg.wParam;
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else if (rc >= WAIT_OBJECT_0 && rc < WAIT_OBJECT_0 + nwaitCount)
{
int nlndex = rc - WAIT_OBJECT_0;
}
else if (rc >= WAIT_ABANDONED_0 && rc < …
Run Code Online (Sandbox Code Playgroud)