小编Rya*_*Liu的帖子

const ++在C++中的行为

这是我的问题,问题出在评论中

const int a = 5;
const_cast<int&>(a)=7; //throw over const attribute in a,and assign to 7
std::cout<<a<<std::endl; //why still out put 5!!!!!!!!!!
Run Code Online (Sandbox Code Playgroud)

谁可以告诉我为什么,有些书籍会考虑这些问题来推荐?谢谢!

c++ const-cast undefined-behavior

5
推荐指数
1
解决办法
510
查看次数

如何实现通用min?

当我写作

T min(T& a,T& b)
{return a<b?a:b;}
Run Code Online (Sandbox Code Playgroud)

并且调用min(3,4),它将产生错误.

如何实现通用min?

c++ templates

4
推荐指数
1
解决办法
194
查看次数

如何将int转换为wstring?

我想将整数值(int)转换为std :: wstring.
做这个的最好方式是什么?
由于某些原因,我不能使用to_wstring.

任何帮助,将不胜感激.

c++

2
推荐指数
1
解决办法
8757
查看次数

在python中,++是什么意思?

我读了这样的剧本

for ... :
   for ...:
      ++i
Run Code Online (Sandbox Code Playgroud)

但是什么++意思呢?是++运营商是Python?

python

0
推荐指数
2
解决办法
458
查看次数

C++ lambda值无法捕获

这是我的代码,我想在c ++中像javascript一样测试闭包.为什么编译器会产生此消息?"testLambda.cpp:在lambda函数中:testLambda.cpp:8:11:错误:'a'未被捕获"

    #include <iostream>
    #include <functional>
    std::function<bool(int)> returnLambda(int a){
        auto b  = 1;
        auto c  = 2;

        return [&](int x)
        {   return x*(b++)+c+a == 0;};
    }
    auto f = returnLambda(21);
    int main(){
        auto c = f(1);
        auto b = f(1);

        std::cout<<c<<b<<std::endl;
        return 0;
    }
Run Code Online (Sandbox Code Playgroud)

c++ lambda

0
推荐指数
1
解决办法
1371
查看次数

为什么python范围(0,x**2 + 1)非常慢?

这是我的代码

def(x):
    for i in range (0,x**2+1):
        ...
Run Code Online (Sandbox Code Playgroud)

但我发现它很慢!! 谁能告诉我原因,谢谢!

python

-2
推荐指数
1
解决办法
108
查看次数

标签 统计

c++ ×4

python ×2

const-cast ×1

lambda ×1

templates ×1

undefined-behavior ×1