小编pol*_*pts的帖子

boost :: bind在std :: transform中连接字符串

我试图在std :: transform内使用boost :: bind连接两个字符串

假设我的类有两个方法来获取两个字符串(第一个和第二个),并且conatiner是字符串向量,我试图做如下

struct Myclass
{
   std::string getFirstString() {return string1}
   std::string getSecondString() {return string2}

   private:
     std::string string1;
     std::string string2;
}

Myclass myObj;

std::vector<string > newVec;
std::vector<myObj> oldVec;
std::transform (oldVec.begin(), oldVec.end(), std::back_inserter(newVec), boost::bind(&std::string::append,boost::bind(&getFirstString,  _1),boost::bind(&getSecondString, _1 ) ) ); 
Run Code Online (Sandbox Code Playgroud)

但是,我得到错误说

error: cannot call member function 'virtual const getSecondString() ' without object
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么?

c++ boost boost-bind

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

c ++ 11相当于java atomiclongarray

我正在研究Java库的C++端口.其中一个问题是我无法找到Java的AtomicLongArray.任何人都知道c ++ 11中是否有任何相同的东西或者如何实现类似的功能?我看过C++ 11原子但找不到任何东西.

c++ java multithreading atomic c++11

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

Java varargs在C++中的等价物

我有一个用Java编写的函数,它接受varargs作为参数.我想将该函数移植到C++.我试图搜索,但我得到的最接近的是使用参数列表的std :: vector.将varargs转换为C++的最佳方法是什么?功能如下.

public EventHandlerQueue<T> get (final EventHandler<T> ... handlers)
{
     // Do something with handlers
     return new EventHandlerQueue<T>(handlers)
}  
Run Code Online (Sandbox Code Playgroud)

c++ variadic-functions

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

从迭代器对c ++创建stl向量

我试图从迭代器对创建一个stl向量,我不知道向量可能有多少元素.它可能只有一个元素.

#include <iostream>
#include <vector>

int main()
{
    using namespace std;

    vector<int> vect;
    for (int nCount=0; nCount < 6; nCount++)
        vect.push_back(nCount);

    vector<int> second(vect.begin(), vect.begin() );

    vector<int>::iterator it; // declare an read-only iterator
    it = second.begin(); // assign it to the start of the vector

    while (it != second.end()) // while it hasn't reach the end
    {
        cout << *it << " "; // print the value of the element it points to
        it++; // and iterate to the next element …
Run Code Online (Sandbox Code Playgroud)

c++ stl stdvector

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