请参阅以下代码段.我想使用std::bindfor重载函数foobar.它只调用没有参数的方法.
#include <functional>
#include <iostream>
class Client
{
public :
void foobar(){std::cout << "no argument" << std::endl;}
void foobar(int){std::cout << "int argument" << std::endl;}
void foobar(double){std::cout << "double argument" << std::endl;}
};
int main()
{
Client cl;
//! This works
auto a1 = std::bind(static_cast<void(Client::*)(void)>(&Client::foobar),cl);
a1();
//! This does not
auto a2= [&](int)
{
std::bind(static_cast<void(Client::*)(int)>(&Client::foobar),cl);
};
a2(5);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用visual studio 2012.我有一个模块,在通过xml遍历相应的路径后,我必须从硬盘中读取一大堆文件.为此我正在做
std::vector<std::thread> m_ThreadList;
Run Code Online (Sandbox Code Playgroud)
在一个while循环中,我将一个新线程推回到这个向量中,类似于
m_ThreadList.push_back(std::thread(&MyClass::Readfile, &MyClassObject, filepath,std::ref(polygon)));
Run Code Online (Sandbox Code Playgroud)
我的C++ 11多线程知识是有限的.我在这里的问题是,如何在特定核心上创建一个线程?我知道vs2012中的parallel_for和parallel_for_each,可以充分利用内核.但是,有没有办法使用标准C++ 11?
当我右键单击Visual Studio 2008 IDE中的文本编辑器时,弹出菜单的速度会变慢.视觉工作室中是否有任何可以控制此行为的设置?
我是一个初学者,所以,如果这听起来太微不足道,请耐心等待。当我在网上搜索这个时,我得到的结果显示了如何做到这一点。我的问题是我们为什么要这么做?
我正在使用导出的类
class __declspec(dllexport) myclass
{
private:
template __declspec(dllexport) class std::map<myclass*,int>;
std::map<myclass*,int>m_map;
//something
};
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我得到一个警告C4251说m_map:类'std :: map <_Kty,_Ty>'需要让dll接口供myclass类的客户端使用.
关于我如何解决这个问题的任何想法?
阿图尔
我正在开发一个C++中的矩阵计算库.为此,我想使用模板.在做了一些模板元编程之后,我意识到我最终会在Templatise Matrix类中公开我的实现.当你公开那个特定的模板类时,有没有办法在头文件中模糊模板类的实现?如果是,那怎么办?
我试图使用for_each而不是正常的for循环.但是,由于我是C++ 11的新手,我有点卡住了.我的意图是一起使用for_each和lambda表达式.有任何想法吗 ?我正在使用visual studio 2010.
问候,
Atul
这是代码.
#include "stdafx.h"
#include <algorithm>
#include <memory>
#include <vector>
#include <iostream>
using namespace std;
struct Point
{
union
{
double pt[3];
struct {double X,Y,Z;};
struct {double x,y,z;};
};
Point(double x_,double y_,double z_)
:x(x_),y(y_),z(z_)
{}
Point()
:x(0.0),y(0.0),z(0.0)
{}
void operator()()
{
cout << "X coordinate = " << x << endl;
cout << "Y coordinate = " << y << endl;
cout << "Z coordinate = " << z << endl;
}
};
int …Run Code Online (Sandbox Code Playgroud) 从工厂返回指针的最佳方法是什么?它应该是一个std::unique_ptr或者std::shared_ptr只是一个原始指针?
另外,有人告诉我,std::unique_ptr如果有遏制,std::shared_ptr如果有聚集,应该去.这是正确的方法吗?
我有一个二进制数,我想用十进制表示.数量如下:
Binary = 1000 11100000 00000000 00000000 00000000 00000000 01101110 10110000 10100101
Run Code Online (Sandbox Code Playgroud)
其等效的十六进制表示如下:
Hexadecimal = 08 E0 00 00 00 00 6E B0 A5
Run Code Online (Sandbox Code Playgroud)
我正在使用Windows 7并尝试在程序员模式下使用计算器与Bin(二进制)和Qword.但是,它有64位的限制.
问题:
我试图在c ++中使用sizeof运算符做一些事情.
请参阅以下代码段.
http://ideone.com//HgGYB
#include <iostream>
using namespace std;
int main()
{
int *pint = new int[5];
int temp = sizeof(*pint);
cout << "Size of the int array is " << temp << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我期待输出为5*4 = 20.令人惊讶的是它来到4.任何想法?
我是STL的新手.我编写了一个Template Base类,如下所示
template <class T>
class Base
{
public:
//Constructor and Destructor ..
Base();
virtual ~Base();
virtual foo() = 0;
};
Run Code Online (Sandbox Code Playgroud)
现在,我想设计我的框架,以便我的继承类将公开派生自这个类,并将在各自的实现中实现foo.问题是我不知道如何从Template Base类继承?如下......
template class<T>
class Derived : public Base<T>
{
// Implementation of Derived constructor etc and methods ...
};
Run Code Online (Sandbox Code Playgroud)
或者普通的C++方式
class Derived : public Base
{
};
Run Code Online (Sandbox Code Playgroud)
有什么建议 ?另外,对于像我这样的新手开始使用STL的任何信息,我将不胜感激......
此致,
Atul