小编Jac*_*son的帖子

C++ 函数参数中的指针与引用

我想知道如何让函数改变两个变量(返回和另一个变量),我偶然发现在参数(我理解是指参数的地址)之前用“&”调用函数,然后在整个函数中,用'*'符号引用它(我猜这是一个“取消引用”,意味着它改变了地址处的对象)。

不管怎样,这一切都很好,然后有朋友说你可以直接用变量调用函数,在header中用&前面的变量引用变量,并在整个函数中正常对待它。这似乎更容易,那么为什么网络上没有更多关于它的信息呢?一种风格比另一种更正确吗?

void foo(int &junk)  //The way the friend said
{
    junk++;
}

void oof(int *junk) //what I found, and what the internet seems full of
{
    (*junk)++;
}

int main ()
{
    int junk=1;
    std::cout << junk << "\n";
    foo(junk);
    std::cout << junk << "\n";
    oof(&junk);
    std::cout << junk;
}
Run Code Online (Sandbox Code Playgroud)

这输出:

1
2
3
Run Code Online (Sandbox Code Playgroud)

所以一切正常,我想。

c++ pointers

5
推荐指数
1
解决办法
5062
查看次数

身份验证无法将node.js与PostgreSQL连接

我有一些使用PostgreSQL设置的数据库,我能够从psql REPL那样做我需要的一切,但当我尝试通过同一台机器上的node.js访问它时,我收到一个password authentication filed for user"[my user name]"错误.

根据在线教程,我的数据库访问代码是这样的:

var pg = require('pg');
var path = require('path');
var connectionString = require(path.join(__dirname, '../', '../', 'config'));

var client = new pg.Client(connectionString);
client.connect();
var query = client.query('CREATE TABLE items(id SERIAL PRIMARY KEY, text VARCHAR(40) not null, complete BOOLEAN)');
query.on('end', function() { client.end(); });
Run Code Online (Sandbox Code Playgroud)

但是由于我已经使用我自己的一些函数设置了表,我只是尝试在POST上访问这些函数,其中:

var express = require('express');
var router =  express.Router();
var pg = require('pg');
var path = require('path');
var connectionString = 'postgres://localhost:5432/[My User Name]?ssl=true;

router.post('/locations', function(req,res) {
    var client …
Run Code Online (Sandbox Code Playgroud)

postgresql node.js express

4
推荐指数
1
解决办法
3578
查看次数

标签 统计

c++ ×1

express ×1

node.js ×1

pointers ×1

postgresql ×1