鍍金池/ 問答/ C++問答
乖乖噠 回答

先把代碼排版好

根據(jù)你的錯(cuò)誤信息,你的編譯的命令行應(yīng)該有誤,順便一道貼出來看看

個(gè)人猜測,你是沒有加入Student.cpp的編譯:

cc main.cpp Student.cpp -o a.out
背叛者 回答

用數(shù)組的reduce方法
let arr = [[1, 2], [3, 4], [5, 6]]
let list = []
arr.reduce((pre, current, index, arr) => {

list = []
for (let i = 0; i < pre.length; i++) {
    for (let j = 0; j < current.length; j++) {
        list.push(+(pre[i] + '' + current[j]))
    }
}
return list

})

console.log(list)

void butler();多了個(gè)分號(hào)

撥弦 回答

收到RST的socket,第一次觸發(fā)可讀,read返回-1并設(shè)置errno,不close得話,繼續(xù)觸發(fā)可讀,再read便會(huì)返回0。

祉小皓 回答

可以去看一下二叉樹的遞歸,相信應(yīng)該有幫助

舊顏 回答
const http = require('http');
var querystring = require('querystring');
const postData = JSON.stringify(
    {
        "body":
          {
            "content":"拜訪",
            "visitor_name":"李四",
            "visitor_company_name":"",
            "check_in_plcae":"南京",
            "visitor_type":"02",
            "host":"01",
            "visitor_num":"11",
            "photo":""
          }
      }
  );
  console.log(postData);
  
  const options = {
    hostname: '',
    port: 8089,
    path: '',
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Content-Length': Buffer.byteLength(postData)
    }
  };
  
  const req = http.request(options, (res) => {
    console.log(`狀態(tài)碼: ${res.statusCode}`);
    console.log(`響應(yīng)頭: ${JSON.stringify(res.headers)}`);
    res.setEncoding('utf8');
    res.on('data', (chunk) => {
      console.log(`響應(yīng)主體: ${chunk}`);
    });
    res.on('end', () => {
      console.log('響應(yīng)中已無數(shù)據(jù)。');
    });
  });
  
  req.on('error', (e) => {
    console.error(`請(qǐng)求遇到問題: ${e.message}`);
  });
  
  // 寫入數(shù)據(jù)到請(qǐng)求主體
  req.write(postData);
  req.end();

最后我通過這種方式發(fā)送了過去

喵小咪 回答

問題已經(jīng)解決

結(jié)構(gòu)體中定義的是 string 類型,string 的長度可以是 3 或者6 任意長度,導(dǎo)致結(jié)構(gòu)體占用空間大小不確定。

傻叼 回答

在C++里使用C庫的函數(shù)時(shí),你加了 extern "C" { } 嗎? 否則就會(huì)鏈接找不到。

痞性 回答

new is not an operator!

In c++, new and operator are both keywords. new int(x) is a(n) (new-)expression. operator new is a function. new operator in your title is new-expression indeed. new-expression will invoke oeprator new function.

placement new的作用就是在operator new分配好的內(nèi)存上執(zhí)行對(duì)象的構(gòu)造,
Yes, that's true. To help you understand, here is a sample:
char* ptr = new char[sizeof(T)]; // ptr use a new-expression(newchar [sizeof(T)] to allocate memory, char is guaranteed to be sizeof 1
T* tptr = new(ptr) T;            // Here is placement new

In a nutshell, placement new will use already allocated memory to construct the object. Where is the already allocated memory from? Either from new expression(free store) or allocated from activation record like int buffer[10], both ok.

那么new operator使用了operator new來申請(qǐng)內(nèi)存之后是使用了placement new嗎?如果沒有話是怎么構(gòu)造的呢?和placement new有關(guān)系嗎?

Above is my answer to your questions

BTW, from the case int buffer[10], we can see pre-new-expression is not a must for placement new(however, note that placement new itself is a new-expression, which will invoke operator new function because all it does is just construct here). If your question is "will placement new always be after operator new/new-expression", it will be a good question.

Update

One year ago, I was confused about how to combine operator new with the constructor then asked a question, FrankHB answered my question: https://tieba.baidu.com/p/508... Now, look back to this question, it is a X-Y question, what really confused me was how does new expression invoke constructor, so it is not related to placement new. Hope it will also inspire you.

Update again

所以我認(rèn)為或許自己和您一年前的疑問相似,內(nèi)存申請(qǐng)和構(gòu)造函數(shù)這兩個(gè)過程是如何結(jié)合的呢?
the word combination(結(jié)合) is not properly now(I also make such mistake as said above), let me re-organize my wording:

new expression does two things:

  1. allocate memory
  2. initialization of the object

You and I(one year ago) are both confused about how does compiler initialize the object(via constructor or else) after allocating. Yes, I mentioned compiler, because C++ standard guarantee new will do the two things, but didn't how to, so, its compiler's work. So, it is not c++'s work, just compiler's. Now, we can see the assembly:

struct Foo
{
    Foo(int i) {}
};
int main()
{
    auto *a = new Foo(1);
}  

-O0:

Foo::Foo(int):
        push    rbp
        mov     rbp, rsp
        mov     QWORD PTR [rbp-8], rdi
        mov     DWORD PTR [rbp-12], esi
        pop     rbp
        ret
main:
        push    rbp
        mov     rbp, rsp
        push    rbx
        sub     rsp, 24
        mov     edi, 1
        call    operator new(unsigned long)
        mov     rbx, rax
        mov     esi, 1
        mov     rdi, rbx
        call    Foo::Foo(int)
        mov     QWORD PTR [rbp-24], rbx
        mov     eax, 0
        add     rsp, 24
        pop     rbx
        pop     rbp
        ret

codes related the new expression is follows: a

    mov     edi, 1
    call    operator new(unsigned long)
    mov     rbx, rax
    mov     esi, 1
    mov     rdi, rbx
    call    Foo::Foo(int)
    mov     QWORD PTR [rbp-24], rbx
    

Now, it is clear enough, right? assemble calls two procedures, oeprator new and Foo::Foo(int)

That's all, cheers!

So, your question is how the two combined?

久舊酒 回答

void fun(int *q,int *p,int *w);修改的是指針指向的內(nèi)容(a, b, c)。void fun_(int *q,int *p,int *w);修改的是指針本身,而不是指向的內(nèi)容。

妖妖 回答

我有用過這個(gè),你不要用他那個(gè)數(shù)據(jù)來平均等分,而是用另一種方法,比如你的有9份,有3種顏色,那就是分成3份,我目前知道的就這樣解決,我也沒有找到整數(shù)的api??傊阋昧硪环N方法給他搞成整數(shù)。

怪痞 回答

C++標(biāo)準(zhǔn)只規(guī)定了編譯器可以幫我們把一個(gè){}定義的常量數(shù)組轉(zhuǎn)換為一個(gè)initializer_list對(duì)象,這樣接受initializer_list為參數(shù)的函數(shù)(通常是各種構(gòu)造函數(shù)),就可以接受{},通過這種方式擴(kuò)展了語法,使我們可以像初始化普通數(shù)組那樣初始化容器,簡化了代碼。

但不要把initializer_list當(dāng)做一個(gè)普通的(容器)來用。

在GCC(4.8)的實(shí)現(xiàn)版本里,initializer_list的構(gòu)造函數(shù)被實(shí)現(xiàn)為private。除了通過{}讓編譯器幫你構(gòu)造,你不能構(gòu)造一個(gè)有效的initializer_list。

namespace std
{
  /// initializer_list
  template<class _E>
    class initializer_list
    {
    public:
      typedef _E                value_type;
      typedef const _E&         reference;
      typedef const _E&         const_reference;
      typedef size_t            size_type;
      typedef const _E*         iterator;
      typedef const _E*         const_iterator;

    private:
      iterator                  _M_array;
      size_type                 _M_len;

      // The compiler can call a private constructor.
      constexpr initializer_list(const_iterator __a, size_type __l)
      : _M_array(__a), _M_len(__l) { }

    public:
"/usr/include/c++/4.8/initializer_list" [readonly] 107 lines --17%--                   

在VC++ 2017的的實(shí)現(xiàn)版本里,initializer_list的構(gòu)造函數(shù)是public。

constexpr initializer_list(const _Elem *_First_arg,
        const _Elem *_Last_arg) _NOEXCEPT
        : _First(_First_arg), _Last(_Last_arg)
        {    // construct with pointers
        }

所以下面的代碼在VC++2017上是ok的:

#include <iostream>

void test(std::initializer_list<int> lst) {
    for (auto l : lst)
        std::cout << l << std::endl;
}

int main() {
    int a[] = { 1, 2, 3, 4 };

    test({ 1, 2, 3, 4 }); // c++ standard 

    test(std::initializer_list<int>(a, a + 4)); // compile error in gcc 4.8 but ok in vc++2017

    return 0;
}

但這是不被保證的。

C++通過庫代碼配合編譯器的方式支持了一種新的語法,這可能是讓人容易困惑的原因。

熊出沒 回答

1.cd到redis文件夾,找到redis.conf
2.把daemonize設(shè)置為yes
3.輸入./redis-server ../redis.conf 這個(gè)路徑不確定根據(jù)個(gè)人的實(shí)際安裝情況而定,反正就是找到redis-server的路徑 以redis.conf的路徑啟動(dòng)

來守候 回答

C++的話可以使用GetAdaptersInfo函數(shù)來獲取相關(guān)網(wǎng)卡信息。
提供一個(gè)實(shí)例鏈接(實(shí)例存在內(nèi)存泄露):鏈接描述

官方實(shí)例:鏈接描述

墨小白 回答

解決辦法如下。post這樣發(fā)送請(qǐng)求就好了

axios.post( apiUrl, qs.stringify({name: 'testName', pass: 'testPass'}), {
  headers: {
     'Content-Type': 'application/x-www-form-urlencoded'
  }
}).then(//***).catch(//***)
  1. install qs module, and use qs.stringify(dataObject) to format your data object
  2. add axios config
{
  headers: {
     'Content-Type': 'application/x-www-form-urlencoded'
  }
}
維他命 回答

1.剛買的這臺(tái)機(jī)器磁盤還用分區(qū)嗎?
不需要,直接使用即可

2.如果要分區(qū),大概要怎么來分區(qū)呢?
忽略

3.如果不用分區(qū),對(duì)以后磁盤擴(kuò)容會(huì)有什么影響嗎?
一般服務(wù)器無非就是一些日志,一般40G也夠用了,如果你服務(wù)器需要存儲(chǔ)大量文件,建議你使用OSS文件存儲(chǔ);
當(dāng)然阿里云的服務(wù)器你也是可以之后購買磁盤進(jìn)行擴(kuò)容,沒有任何壓力。

離夢(mèng) 回答

看少俠這代碼,RoomBusiness這個(gè)類應(yīng)該是以單例模式寫的吧,所以兩種方法沒區(qū)別

絯孑氣 回答

謝邀先!
不過先提醒你稍微學(xué)一下markdown的語法,把語句標(biāo)示出來,否則直接插入的語句可能會(huì)被系統(tǒng)處理而不能表達(dá)完整的意思了。請(qǐng)先處理這點(diǎn)。

練命 回答

1、PHP對(duì)遞歸是有限制的,遞歸次數(shù)過多就會(huì)出現(xiàn)溢出報(bào)錯(cuò)。
2、在理論上,所有的遞歸都可以用循環(huán)替代。
3、生成HTML樹的難點(diǎn)在于html的閉合標(biāo)簽如:</ul>。

可以參考:PHP無限級(jí)分類的實(shí)現(xiàn)(不使用遞歸) http://www.cnblogs.com/rainma...

grid[i] 是個(gè)int* 不錯(cuò),但是你的grid[i]指向哪里了你?你沒有為它分配內(nèi)存。

函數(shù)傳入的grid有什么意義呢?