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