ICode9

精准搜索请尝试: 精确搜索
  • c – 调用std :: set :: find时避免使用const_cast2019-10-08 00:07:59

    有没有什么好方法可以避免下面的const_cast,同时保持const的正确性? 没有const_cast,下面的代码不会编译. set :: find获取对set的键类型的const引用,因此在我们的例子中它保证不改变传入的指针值;但是,没有任何保证不改变指针指向的内容. class C { public: std::set<int*> m_s

  • c – const_casting问题2019-09-29 17:05:52

    参见英文答案 > Two different values at the same memory address                                    6个 我有以下代码: int main(){ const int a = 1; const int* b(&a); int* c = const_cast<int*>(b); *c = 29; cout<<*c<<a

  • c – 这是const_cast的未定义行为吗?2019-09-26 08:07:26

    参见英文答案 > behavior of const_cast in C++                                     3个 这里发生了什么? const int a = 0; const int *pa = &a; int *p = const_cast<int*>(pa); *p = 1; // undefined behavior ?? cout << a << *p; //

  • c – 如何使用const_cast?2019-09-25 23:07:27

    我的Student类中有一个私有变量,定义为: const int studentNumnber; 我正在尝试为Student编写一个复制构造函数,我需要抛弃constness来执行此操作,遗憾的是我不明白如何使用std :: const_cast. 这是我在我的复制构造函数中尝试做的事情: Student(const Student & s)

  • c – const_cast的奇怪行为[复制]2019-09-25 20:04:45

    参见英文答案 > Two different values at the same memory address                                    6个 请考虑以下代码: 我声明一个新的引用结束赋值给一个via const_cast.然后我只是增加参考值打印地址和值. #include <iostream> using

  • c – 使用const_cast的自动类型推断不起作用2019-07-31 02:05:46

    在我的工作中,const_cast的使用在某些情况下是不可避免的. 现在我必须const_cast一些非常复杂的类型,实际上我不想在const_cast< Clutter>中写出所有这种类型的混乱.表达式,特别是如果Clutter非常长. 我的第一个想法是编写const_cast<>(myType),但是我的编译器无法推导出myType的非

  • c – 抛弃方法的常数2019-07-27 09:08:12

    作为我之前的问题(Writing to class member through const &)的后续,是否也很好地定义并正确抛弃类成员方法的常量? class A { public: A() : a(5) { } int run() const { std::cout << "a: " << a << std::endl; int& x = (in

  • c – const_cast转换为左值引用不会删除constness2019-07-22 21:07:39

    我想了解以下两种情况的区别. const uint32_t v0 = 0; const uint32_t v1 = 1; const_cast<uint32_t&>(v0) = v1; std::cout << v0 << std::endl; 结果如下: 0 然而, struct S { const uint32_t v0; S() : v0( 0U ) {} } s; const_cast<uint32_t&&g

  • c – 具有不同const限定符的2种类型之间的转换2019-07-22 15:06:36

    这是我想要使用的代码的一个简短示例: template <class T> class B { public : bool func1(const T& t) { // do something } }; class A { B<int*> b; public: void func2(const int* a) { b.func1(a); } }; 我收到这个错误: 错误C

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有