在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/ C++問答
心上人 回答

借花獻佛
https://blog.csdn.net/u010003...
另外MongoDB 4.0已經(jīng)開始支持事務了

妖妖 回答

是的,一個類的public static方法可以靜態(tài)調(diào)用

夏木 回答

VMT is implementation dependent, so topics should be limited to compilers implementations rather than c++ itself.

那么虛表是在什么時候生成的呢. 是在構(gòu)造函數(shù)執(zhí)行之前還是在構(gòu)造函數(shù)之后之后呢?

For Most compilers, virtual table pointer initializes __vptr at constructor's initializer list.


而且虛表存放在哪里呢?

What confuses you is where __vptr is(not VMT, because VMT just consists of the addresses of trivial non-virtual functions which can be invoked by __vptr), then:

Compilers have multiple choices(all as a hidden member), you can refer to here

Summary: Where is the __vptr stored in an object (first or last are the usual answers).

Of course, you can implement VMT with c, then you will not ask such questions.

BTW, this is not good (even is a bad) question, because you even haven't searched it on google before asking, so -1.

Update:

Wikipedia is also your friend.

萌二代 回答

因為&&的優(yōu)先級比||高,所以你給的例子去掉括號也不影響結(jié)果。加上括號只是使代碼更易讀。

但是有時候括號是必須的,比如a && (b || c),如果去掉括號結(jié)果就變成了(a && b) || c。

憶往昔 回答

inspect只是為了查看容器里面的值的時候用的,你這里沒有調(diào)用,當然也不會執(zhí)行

懶洋洋 回答

關(guān)鍵字 qqwry 應該個個語言都有實現(xiàn). 這種速度最快, 成本最低, 準確率較好

墨染殤 回答

The statement:

    if(location > listSize++ || location < 1 )
        cout<<"Please enter correct value."<<endl;

can be considered like

    if(location > listSize || location < 1 )
    {
        ++listSize;
        cout<<"Please enter correct value."<<endl;
    }
    

From the C++ Standard (5.2.6 Increment and decrement)

1 The value of a postfix ++ expression is the value of its operand. [ Note: the value obtained is a copy of the original value —end note ]...

So, it will change listSize's value(because of ++listSize;), which is not you hope to see.

悶油瓶 回答
class SparseMat {
public:
    SparseMat(int MAXROW, int MAXCOL, int NonZeroterms);
    SparseMat MAT_transpose(SparseMat b);
private:
    int Rows, Cols, NonZeroterms;
    Trituple* SMArray;
};

SparseMat::SparseMat(int MAXROW, int MAXCOL, int NonZeroterms)
    :Rows(MAXROW), Cols(MAXCOL), NonZeroterms(NonZeroterms)
{
     SMArray = new Trituple[NonZeroterms];
}
愛是癌 回答

推薦@pezy 大佬寫的設(shè)計模式專欄。

設(shè)計模式

野橘 回答

拋磚引玉

  • 一臺服務器上已經(jīng)安裝了Nginx并啟動監(jiān)聽80端口,但此時你又下載一個Apache想啟動也去監(jiān)聽80端口,這時服務器就不讓了,會提示端口被占用,這就是一個端口對應一個應用程序。
  • 當你訪問一個網(wǎng)址時,默認會訪問80端口,假設(shè)服務器使用Nginx,當Nginx監(jiān)聽到有客戶請求自己監(jiān)聽的80端口時,會根據(jù)請求做出相應的相應,至于為什么可以同時鏈接多個用戶,那得看服務器的本身配置了,可以同時允許多少個用戶同時訪問,若是僅允許一個,那么第一個進來了,接下來的就順次排隊,服務器處理一個之后會接下往下處理
乖乖噠 回答

先把代碼排版好

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

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

cc main.cpp Student.cpp -o a.out
尛曖昧 回答

主要原因就是unique_ptrshared_ptr更輕,沒有運行時負擔,所以unique_ptr的刪除器是編譯期確定的。

兩個unique_ptr即使指向類型相同,若刪除器不同,也屬于不同類型。unique_ptr的刪除器已經(jīng)內(nèi)植于類型,所以不需要存儲一個刪除器對象就知道刪除器在哪?!邦愋蛢?nèi)植”過程是編譯期確定的,刪除過程的代碼的運行當然是運行期運行的。

shared_ptr就不同,構(gòu)造函數(shù)傳進來一個實實在在的對象,它存儲起來用?!皩ο蟠鎯Α边^程是運行期確定的,刪除過程的代碼的運行當然也是運行期運行的。shared_ptr的靈活性更高。

爆扎 回答

既然你了解了引用折疊, 我相信你也應該知道了forward就是一簡單的static_cast<T&&>t.

此函數(shù)void process(T&& t)是有問題的, 它依舊是一個universal reference/forwarding reference , 只有void process(int&& t)這樣明確是右值引用你才能稱作rv, 對吧. 所以先改下函數(shù)并簡化代碼:

template <typename T> void process(const T& t) { cout << "const T&" << endl; }
template <typename T> void process(T&& t)      { cout << "T&&" << endl; }
void test(...) { process(...) ;}

因為forward只是一個轉(zhuǎn)發(fā)(從上面的實現(xiàn)配合引用折疊也是很好理解的), 并且能保留原有的ref-qualifier和const-qualifier, 所以被稱作完美轉(zhuǎn)發(fā), 因此你可以把test里面的process繼續(xù)簡化掉:

int non_const_a = 1;
int const const_a = 1; 
template <typename T> void process(const T& t) { cout << "const T&" << endl; }
template <typename T> void process(T&& t)      { cout << "T&&" << endl; }
test(1); // T&&
test(non_const_a); // T&&
test(const_a); // const T&

有沒有發(fā)現(xiàn)什么? 整個過程其實就是簡化成左值, 右值, 加上const-qualifier對process的函數(shù)重載決議了.

無論T&&還是const T&都和標題中的forward, 右值引用沒什么關(guān)系了

這下應該明白了吧? 只有const的左值才會匹配const T&, 其他都會匹配T&&. 很明了的一個重載決議.


繼續(xù), 可能OP會想, 如果我這么重載呢?

template <typename T> void process(const T& t) { cout << "const T&" << endl; }
template <typename T> void process(const T&& t)      { cout << "T&&" << endl; }

都有const呀, 此時該怎么辦呢? 編譯器是不是就gg了?

clipboard.png

簡單的說, 此時const T&&不再是人見人愛花見花開的, forwarding reference, 因為有了const-qualifier, 所以退化成了rvalue-reference了. g(i)妄想傳個左值進去不是作么. 比如這樣的例子:

void f(int&& a) {} 
int main()
{
    int a = 1;
    f(a);
}

prog.cc:5:12: error: cannot bind rvalue reference of type 'int&&' to lvalue of type 'int'

 f(a);

有了以上鋪墊, OP是不是能想出之前提的問題:

#include <utility>
#include <iostream>

using std::cout;
using std::endl;

template
<typename T>
void process(const T& t)
{
    cout << "const T&" << endl;
}

template
<typename T>
void process(const T&& t)
{
    cout << "const T&&" << endl;
}

template
<typename T>
void test(T&& t)
{
    process(std::forward<T>(t));
}

int main()
{
    int a = 1;
    const int const_a = 1;
    test(1);
    test(a);
    test(const_a);
}
const T&&
const T&
const T&

可見只有右值1匹配了const T&&, 畢竟人家只能匹配右值嘛, 也是應該的.

網(wǎng)妓 回答

編譯時加上 -DCMAKE_PREFIX_PATH=path/to/qt5widgets 試一試

替身 回答

樓主的意思是將二叉樹的空節(jié)點也表示出來嗎?比如說:

               1
              / \
                 3
                / \
               4   5

表示成

               1
             /   \
           nil    3
           / \   / \
          nilnil4  5
          

這樣嗎。
個人想法滿二叉樹可以用數(shù)組保存,那么樓主可以將數(shù)組將二叉樹擴充為滿二叉樹

墨沫 回答

沒有報錯是因為直接將array[3]當做*(array+3)處理嗎?

可以這么理解。以C++的尿性來看,這樣最簡單,最快,也方便各種魔幻用法。檢測越界這種事應該交給庫,或者更高級的語言。

那為什么array[3]array[4]輸出結(jié)果相同?

Visual C++ 編譯器會在調(diào)試模式下把未初始化的內(nèi)存用0xCC填充。如果輸出字符串,就是喜聞樂見的燙燙燙。如果輸出int32,就是-858993460。

[...new Uint8Array(Int32Array.of(-858993460).buffer)].map(e => e.toString(16))
// <- ["cc", "cc", "cc", "cc"]

也可以搜索“補碼在線計算器”自己驗證。

背叛者 回答

用數(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)