Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何将 int 的值复制到新的 const int 中?
由此:
int start= 343;
进入这个:
const int end = start;
如何做到这一点,任何例子?我真的不知道怎么做,请帮帮我-
像这样:
int start = 343; const int end = start;
如果您想确定end是 const,请尝试修改它:
end
end++; // Compile error!
如果你使用 C++,你可以在运行时设置一个常量成员变量:
class M { public: M(int number) : mNumber(number) { } const int mNumber; };