我想要一个带可选参数的函数.但是,VC++抛出了一个我无法理解的错误.代码简单如下:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void myFunction(string something, int w);
int main()
{
myFunction("a string");
int a = 1;
}
void myFunction(string something, int w = 5)
{
cout << something << " - " << w << endl;
}
Run Code Online (Sandbox Code Playgroud)
它抱怨说:
'myFunction': function does not take 1 arguments
Run Code Online (Sandbox Code Playgroud)
但是,如果我在main()之前移动myFunction(),它不会给出错误.到底是怎么回事?请帮忙.谢谢.
我正在关注这个教程。main.cc中的以下声明引起了我的兴趣:
auto say_hello = [](const HttpRequest& request) -> HttpResponse {
HttpResponse response(HttpStatusCode::Ok);
response.SetHeader("Content-Type", "text/plain");
response.SetContent("Hello, world\n");
return response;
}
Run Code Online (Sandbox Code Playgroud)
这显示在调试窗口中。
auto我希望用原始数据类型替换关键字。我已尝试以下操作但失败:
HttpResponse say_hello = [](const HttpRequest& request) -> HttpResponse {...}
Run Code Online (Sandbox Code Playgroud)
有人能告诉我为什么这是错误的吗?正确的解决方案是什么?太感谢了!!!
我知道如何定义int [i],byte [i]等数组.喜欢它,因为我可以使用for循环来运行它们.现在我想用文本框,按钮,标签等花哨的对象做同样的事情......我想知道这是否可行.
如果是的话,怎么办呢?那个对象的名字怎么样?像mytextbox [1],mylabel [2]这样的东西?
我有以下代码:
class MyList
{
private:
public:
int* list;
int size = 0;
int max;
// constructor
MyList(int s)
{
max = s;
size = 0;
if(max > 0)
list = new int[max];
};
// destructor
~MyList()
{
for (int x = 0; x < max; x++)
delete (list + x);
};
};
Run Code Online (Sandbox Code Playgroud)
我试图用析构函数清除内存.但是,它会在第二次迭代时抛出错误.我做错了什么?此外,它不会让我这样做:
delete list[x];
Run Code Online (Sandbox Code Playgroud)
有人能解释一下为什么吗?非常感谢.
我看到这样的代码:
Thread.Sleep();
Run Code Online (Sandbox Code Playgroud)
但从未看到'Thread'声明.'Thread'是否指C#中的主线程?我见过在使用之前声明的其他线程对象,但不是这个.