小编0x4*_*2D2的帖子

std :: find_end的复杂性为Big-O

如何将std::find_end算法的复杂性表示为Big-O表示法?

复杂性std::find_end定义如下:

在大多数(last2 - first2) * (last1 - first1 - (last2 - first2) + 1) 相应谓词的应用程序中.

c++ algorithm complexity-theory

7
推荐指数
1
解决办法
256
查看次数

移动构造函数签名

引用中,它允许constrvalue作为移动构造函数

Type::Type( const Type&& other );
Run Code Online (Sandbox Code Playgroud)

可移动物体怎么样const?即使这在技术上是允许的,是否存在这样的声明有用的情况?

c++ move-constructor c++11

7
推荐指数
1
解决办法
1006
查看次数

将参数包解压缩到另一个模板声明中意味着什么?

我不明白应该如何使用以下功能.当我打电话时A::f我可以省略模板参数,但我不明白为什么.

template <typename... Args>
struct A
{
    template <Args...>
    void f() {}
};

int main()
{
    A<int, bool> a;
    a.f();
}
Run Code Online (Sandbox Code Playgroud)

具体来说,这是什么template <Args...>意思,为什么我可以将模板参数从函数调用中删除f

c++ c++11

7
推荐指数
1
解决办法
288
查看次数

使用std :: shared_ptr和std :: thread编译错误

我正在尝试使用shared_ptrfrom类启动线程Test,我收到此错误:

/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/functional:559:2: note: no known conversion for argument 1 from 'std::shared_ptr<Test>' to 'std::shared_ptr<Test>&'

示例代码:

    std::shared_ptr<Test> test = std::make_shared<Test>();
    std::thread th(&Test::run, test); // Compiler error


    Test* test2 = new Test;
    std::thread th(&Test::run, test2); // okay
Run Code Online (Sandbox Code Playgroud)

注意:在使用VS2013的Windows中,第一个示例工作正常.

c++ c++11

7
推荐指数
1
解决办法
458
查看次数

JavaScript如何在内部存储空值?

我总是想知道JavaScript如何在null内部存储值.null不同于任何价值.我想范围的变量存储在某种结构数组中,每个结构对应一个变量.这个结构是否有某种名为"null"的布尔属性?

我会在V8源代码中自己查找,但我在C++代码中很丢失:(

我在谷歌上找不到任何东西.大多数结果与诸如"如何确定变量是否未定义或为空?"之类的问题有关.或类似的.

javascript c++ null internal

6
推荐指数
1
解决办法
489
查看次数

这是编译错误typedef int(*j)()throw(A)?

#include <iostream>

class A {};

typedef int (*j)() throw(A);  

int f() 
{
    std::cout << "function f" << std::endl;
    return 0;
}

int main()
{ 
    j y = f;
    y();
}
Run Code Online (Sandbox Code Playgroud)

在所有站点和Stroustrup也说会有编译错误,但它编译.标准有变化吗?

c++ typedef visual-studio-2012

6
推荐指数
1
解决办法
270
查看次数

如何在单一设置中合并exe和msi文件?

我正在使用visual studio setup项目创建一个设置,它将创建两个文件,一个是msi,第二个是exe.但我想用它创建单个文件.

.net c#-4.0

6
推荐指数
1
解决办法
3200
查看次数

'std :: string'没有名为'front'的成员

#include <string>
#include <algorithm>
#include <iostream>

int main()
{
    string str;
    string str1;
    int h = 0;
    cin >> str;
    if (str.length() > 10)
    {
        str1 += str.front();
        h = str.length() - 2;
        string s = to_string(h);
        str1 += s;
        str1 += str.back();
        cout << str1;
    }
    else cout << str;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译在XCode中,但不在codeforces.ru/上

 ?an't compile program.cpp:
program.cpp: In function 'int main()':
program.cpp:23:21: error: 'std::string' has no member named 'front'
program.cpp:27:29: error: 'to_string' was not declared in this scope …
Run Code Online (Sandbox Code Playgroud)

c++ string

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

构造函数中的c ++异常安全性

怎么样下面的代码

MyClass a(new Foo(), new Bar());
Run Code Online (Sandbox Code Playgroud)

如果"new Foo()"成功,但"new Bar()"抛出,Foo会泄漏吗?

正在服用

std::unique_ptr<Foo>
Run Code Online (Sandbox Code Playgroud)

要么

std::shared_ptr<Foo>
Run Code Online (Sandbox Code Playgroud)

作为参数,足以防止泄漏?

c++ exception shared-ptr unique-ptr c++11

6
推荐指数
1
解决办法
694
查看次数

operator << friend功能和模板

这是我的代码:

mov.h

#include <iostream>

template< class T>
class Movie {
public:
    Movie(T in) {
        a = in;
    }

    friend std::ostream& operator<<(std::ostream& os, const Movie<T>& movie);
private:
    T a;
};

template<class T>
std::ostream& operator<<(std::ostream& os, const Movie<T>& movie) {
    return os;
}
Run Code Online (Sandbox Code Playgroud)

main.cpp中

#include "mov.h"

int main() {
    Movie<int> movie1(1);

    std::cout << movie1 << std::endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我尝试编译此代码,我得到错误:

Error 1 error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class Movie<int> const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABV?$Movie@H@@@Z) …
Run Code Online (Sandbox Code Playgroud)

c++ templates overloading operators friend

6
推荐指数
1
解决办法
121
查看次数