我知道如果在构造函数中抛出异常,则不会调用析构函数(简单类,没有继承).因此,如果在构造函数中抛出异常,并且有可能没有清理某些堆内存.那么这里最好的做法是什么?让我们假设我必须在构造函数中调用一些函数,它可能会抛出异常.在这种情况下,我总是使用共享指针吗?有什么选择?谢谢!
我在创建新的 psql 用户时遇到问题,因为我无法以“postgres”的身份登录 psql,我试过了
1. sudo -u postgres psql
2. sudo -u postgres createuser img_site -P -s -e
Run Code Online (Sandbox Code Playgroud)
他们都要求输入我不知道的“postgres”密码。我试图更改用户“postgres”的 unix 密码(我知道这很危险),但它仍然告诉我:用户“postgres”的密码身份验证失败。我也试过 GUI pgAdmin 但它是同样的错误。
我不知道是否相关:我创建了一个符号链接
sudo ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/
Run Code Online (Sandbox Code Playgroud)
为了摆脱错误
createuser: could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Run Code Online (Sandbox Code Playgroud) 我找不到可以批量选择多个问题并将它们分配给项目的选项。我只能批量分配标签和其他东西。
我遇到了这个有线代码而且没有崩溃.
#include <stdio.h>
struct s
{
char* c;
char* c2;
};
int main()
{
struct s* p = NULL;
printf("%d\n", &(p->c));
printf("%d\n", &p->c2);
printf("%d\n", &(*p).c2);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
0
4
4
Run Code Online (Sandbox Code Playgroud)
我有几个问题来找我,我无法回答:
在c/c ++中NULL指针总是等于0吗?
如果0恰好是变量的地址会发生什么?
输出似乎是结构成员的偏移地址.这是如何计算的.我的意思是p-> c是c的地址,它不存在,因为p == NULL.如果c的地址不存在,你怎么能通过&p-> c得到c的地址?
取消引用NULL指针是否保证在C/C++中使程序崩溃?(让我们假设在系统中)
为什么例如<select>并且<textarea>是独立标签而不是属性<input>?
当我运行nodemon dist/server/app.js它时,它可以在默认端口上运行,3000并且可以访问我的API。但是,如果我运行nodemon --inspect-brk=localhost:3000 dist/server/app.js,则会收到错误消息,提示“期望WebSockets请求”。怎么了?
例如,我在标头中跟随Bearer JWT,提取令牌本身的一种优雅方法是什么?以后基本上什么都没有Bearer。由于这可以采用其他格式,因此我不希望它始终以开头Bearer。我正在使用node-jsonwebtoken,但没有找到这种方法。
Authorization: Bearer eyJhbGciOiJIUzI1NiIXVCJ9...TJVA95OrM7E20RMHrHDcEfxjoYZgeFONFh7HgQ
我看到了一个冒泡排序代码,最初我认为代码是错误的.但是在编译和运行之后,它让我惊讶它确实有效.我想知道第一个for循环中的第二个语句如何不是条件而是赋值.另外,为什么这段代码不会进入无限循环?
PS:它会产生一个警告:"建议围绕赋值的括号用作真值[-Whatarentheses]"抱怨第一个for循环.令人惊讶的是,这不是一个错误.
#include <iostream>
void bubblesort(int A[], int n)
{
for (bool sorted = false; sorted = !sorted; n--)
{
for (int i = 1; i < n; ++i)
{
if (A[i-1] > A[i])
{
int tmp = 0;
tmp = A[i];
A[i] = A[i-1];
A[i-1] = tmp;
sorted = false;
}
}
}
}
int main()
{
int a[5] = {1,4,5,2,3};
bubblesort(a, 5);
for (unsigned int i = 0; i < 5; ++i)
{
std::cout << a[i] << std::endl; …Run Code Online (Sandbox Code Playgroud) 我有两个重载功能
void foo(std::string value);
void foo(bool value);
Run Code Online (Sandbox Code Playgroud)
我打电话的时候
foo(true ? "a" : "b");
Run Code Online (Sandbox Code Playgroud)
为什么函数需要一个布尔值而不是字符串?
为什么这段代码会给我一个警告:从不兼容的指针类型传递"test"的参数1?我知道这是关于char之前的const,但为什么呢?
void test(const int ** a)
{
}
int main()
{
int a=0;
int *b=&a;
int **c=&b;
test(c);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我有以下代码
@NgModule({
declarations: [
...
],
imports: [
RoutingModule,
SharedModule,
JwtModule.forRoot({
config: {
headerName: 'Authorization',
tokenGetter: () => localStorage.getItem('token’), // <———— this line has problem
whitelistedDomains: ['localhost:4200']
//blacklistedRoutes: ['localhost:3001/auth/', 'foo.com/bar/']
}
})
],
...
})
export class AppModule { }Run Code Online (Sandbox Code Playgroud)
它可以使用ng serve,但运行时出现以下错误ng build --prod
ERROR in Error during template compile of 'AppModule'
Function expressions are not supported in decorators in '?0'
'?0' contains the error at app/app.module.ts(36,22)
Consider changing the function expression into an exported function.
Run Code Online (Sandbox Code Playgroud)
然后我将代码修改为 …
为什么以下代码输出1,而不是0?a || b应该给我1,1 && 0是0吗,对吗?我不认为逻辑操作从右到左进行评估.
int main()
{
printf("%d\n", 1 || 1 && 0);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 在这个文档http://www.cplusplus.com/reference/string/string/npos/ 中已经说过std :: string :: npos是-1.但是当我打印出价值时,它不是.这个价值架构是否依赖?
我的测试非常简单
std::cout << std::string::npos << std::endl;
Run Code Online (Sandbox Code Playgroud)
哪个输出
4294967295
Run Code Online (Sandbox Code Playgroud) c++ ×5
c ×3
node.js ×2
pointers ×2
algorithm ×1
angular ×1
attributes ×1
binary ×1
bubble-sort ×1
const ×1
constructor ×1
debugging ×1
destructor ×1
function ×1
github ×1
html ×1
html5 ×1
javascript ×1
jwt ×1
macos ×1
memory ×1
nodemon ×1
null ×1
overloading ×1
postgresql ×1
psql ×1
sorting ×1
string ×1
struct ×1
tags ×1