const

    3熱度

    1回答

    這可能是一個愚蠢的問題,但我想看看是否有任何最佳實踐來分配CONST或LET變量。我瞭解CONST變量一旦聲明就不能重新分配,但我注意到通過將一個對象分配給一個CONST變量,可以更新該對象的內容。 const person = { name: "John" } console.log(person.name) => //"John" person.name = "Kim" c

    -4熱度

    1回答

    我正在掃描系統上編輯非常長的字符串。對於掃描,我使用一個字符串來包含正在檢查的當前字母。我需要將char[]數組的長度設置爲string變量的長度,但我的長度變量不被視爲常量,即使它被聲明爲const。 string inputScan; cout << "Enter string." << endl; getline(cin, inputScan); const int stringLen

    0熱度

    2回答

    我寫了一個簡單的日誌記錄類,在Windows上使用Visual Studio在C++中支持variadic模板。我創建了一個通用的Log函數模板,其中包含許多專業知識,以滿足可能輸入的通用組合。 #pragma once #include <Windows.h> #include <locale> #include <codecvt> #include <string> #includ

    1熱度

    4回答

    如果我使用mutable與const指針這樣的: class Test { public: mutable const int* ptr; // OK }; 它的正常工作。 但是,如果我用這樣的: class Test { public: mutable int * const ptr; // Error }; 錯誤: prog.cpp:6:

    -3熱度

    1回答

    我想學習C++並創建Vector2類。我在Vector2類中有這個ToString()函數,它允許我將Vector2打印到屏幕上。 我也有這個靜態常量Vector2變量調用了,我也想用這個ToString()函數打印它們但是它給出了一個錯誤。 這是在.h和Vector.Ppp Vector2 :: up實現當我將Vector2 :: up存儲在Vector2 vec中並將其打印爲vec.ToStr

    0熱度

    1回答

    我正在嘗試返回std::map的最大值。 int main() { int N; cin >> N; map<int,int > m; while(N--) { int x; cin >> x; m[x]++; } cout << max_element(m.begin(), m.end(), pred)->fir

    1熱度

    1回答

    代碼: #include "inc.h" #include <string> #include <vector> #include <algorithm> #include <iostream> using namespace std; class tt{ public: tt(int i): i(i) {} int i; bool o

    0熱度

    2回答

    我通過加速C++工作我的方式,現在,我遇到的有關範圍和代碼塊對我而言缺乏基本的瞭解。 有一個鍛鍊章1月底想要你來決定這些代碼是否會運行: #include <iostream> #include <string> int main() { { const std::string s = "a string"; std::cout << s << std::

    1熱度

    1回答

    在這裏面的代碼: int main(int argc, char *argv[]) { class Bar { public: int bar; }; class Foo { public: std::vector<Bar> myBars; Bar &getOneBar() const { for(B

    -3熱度

    1回答

    假設我們有一個函數: import copy def demo_function(list_in) list_out = copy.deepcopy(list_in) list_in.append("howdy") return list_out 請注意,我們追加到list_in而不是list_out。但demo_function實際上不應修改其輸入。我們想要