const

    0熱度

    1回答

    工作情況: template<typename T> class threadsafe_queue { private: mutable std::mutex mut; std::queue<T> data_queue; public: threadsafe_queue() {} threadsafe_queue(const threa

    0熱度

    1回答

    VC++ 2010的問題: const bool bNew = true; const_cast<bool&>(bNew) = false; if(bNew)//bNew is false here, but { int i = 0;//this line will be executed } 爲什麼? 謝謝。

    21熱度

    1回答

    請注意,我用std::thread只是在錯誤得到可讀類型: int main() { const int * first; using deref = decltype(*first); std::thread s = std::remove_const<deref>::type{}; // const int ??? std::thread s2 = de

    8熱度

    1回答

    我看到在Quora的C++中聲明瞭一個參考變量作爲常量。 static constexpr const int& r = 3; 那麼,爲什麼這兩個constexpr和const在單個語句中使用? 這種類型的聲明的目的是什麼?

    1熱度

    3回答

    我知道,在const int *ptr中,我們可以更改地址,但不能更改該值。即ptr將被存儲在讀寫部分(堆棧)中,並且對象或實體將被存儲在數據分段的只讀部分中。所以,我們可以改變指針ptr指向的地址,但不能改變常量的對象。 int main() { const int *ptr=500; (*ptr)++; printf("%d\n",*ptr); } 輸出爲

    4熱度

    6回答

    以下基本代碼是一個相當大的程序的一部分有條件初始化 const int x = foo() == 0 ? bar() : foo(); 但foo()是一個非常昂貴和複雜的功能,所以我無法將它稱爲性能的兩倍,也可能會產生競爭條件並因此獲得不同的值(可能涉及讀取外部資源)。 我想盡可能使代碼儘可能易讀,如果可能的話儘可能短。一種選擇是: const int foo_ = foo(), x = fo

    0熱度

    1回答

    我正在處理第三方庫,在此爲了簡化代碼,我想修改一個結構。 有一個第三方結構 struct structure { const char *c; // ... }; 我有一個函數 void prep(const structure *s) { std::string str("hello"); const char *t_c = s->c; s

    0熱度

    2回答

    您好我目前的功能是這樣的......我想知道如何使用const apiKey作爲數組。以及如何使用'key'=> self::apiKey作爲'key'=> self::apiKey[rand(0,1)]等。請幫助我。 const apiKey = 'api_key_ods000doo123'; public function counter_params($video_ID, $part) {

    1熱度

    2回答

    我注意到在Java中有const關鍵字。它讓我想起了static和final這些變量。 但是爲什麼沒有人真正使用它?

    5熱度

    5回答

    我有一個情況,在這裏我想有一個地圖,不允許添加/初始化之後刪除鍵,但值被允許改變(因此我不能簡單地使地圖const)。即 /*semi-const*/ map<int,int> myMap = initMap(); myMap[1] = 2; // NOT OK, because potentially adds a new key myMap.at(1) = 2; // OK