c++

I'm trying to "modernize" some existing code. I have a class which currently has a member variable "Device* device_". It uses new to create an instance in some initialization code and has a "delete device_" in the destructory. Member functions of this class call many other functions that take a Device* as a parameter. This works well, but to "moderni

C ++

我试图“现代化”一些现有的代码。 我有一个目前有一个成员变量“Device * device_”的类。 它使用new在一些初始化代码中创建一个实例,并在结构中有一个“delete device_”。 这个类的成员函数调用许多其他将Device *作为参数的函数。 这很好,但为了“代码化”代码,我认为我应该将变量定义为"std::unique_ptr<Device> device_"并删除显式调用,这会使代码更安全,更好。 我的问题是这个 - 那么我该如何

ptr be used safely in stl collections?

I am confused with unique_ptr and rvalue move philosophy. Let's say we have two collections: std::vector<std::auto_ptr<int>> autoCollection; std::vector<std::unique_ptr<int>> uniqueCollection; Now I would expect the following to fail, as there is no telling what the algorithm is doing internally and maybe making internal pivot copies and the like, thus ripping away

ptr在stl集合中安全使用?

我对unique_ptr和rvalue移动哲学感到困惑。 假设我们有两个集合: std::vector<std::auto_ptr<int>> autoCollection; std::vector<std::unique_ptr<int>> uniqueCollection; 现在我期望以下内容失败,因为没有说明算法在内部执行什么操作,并且可能会制作内部数据透视副本等,从而剥离掉auto_ptr的所有权: std::sort(autoCollection.begin(), autoCollection.end()); 我明白了。 编译器正确地禁

Native to C++ CLI unresolved symboles

We have an excellent MFC/C++ project that handles the data to and from a legacy database. All classes are exported with AFX_EXT_CLASS (which is dllexport if i am not misunderstanding it). I am currently writing a wrapper so that we can use it in C# applications. This is my first real wrapper, so please bear with me. This is what i have done: Compiled the project with /Yc /Gm- /Clr. It pro

原生C ++ CLI未解析符号

我们有一个优秀的MFC / C ++项目,可处理传入和传出数据库的数据。 所有类都与AFX_EXT_CLASS(如果我不误解它,这是dllexport)导出。 我目前正在编写一个包装器,以便我们可以在C#应用程序中使用它。 这是我第一次真正的包装,所以请忍受我。 这就是我所做的: 用/ Yc / Gm- / Clr编译项目。 它会生成一个.lib和一个.dll。 我有权访问源代码,因此我在C ++ / Cli项目中添加了头文件的路径。 因此它承认类型。 我

Template functor with any parameters

I'm trying to create template functor, which will take as arguments object and member function with any number of parameters. I can't figure out how to write the code correctly with templates. template<typename ItemT, class T, typename ...Args> struct Builder { ItemT operator()(T& object, ItemT (T::*method)(Args...), Args && ... args) { return

具有任何参数的模板仿函数

我试图创建模板仿函数,它将使用任意数量的参数作为参数对象和成员函数。 我无法弄清楚如何使用模板正确编写代码。 template<typename ItemT, class T, typename ...Args> struct Builder { ItemT operator()(T& object, ItemT (T::*method)(Args...), Args && ... args) { return (object.*method)(std::forward<Args>(args)...); } }; struct Object { int metho

Calling a templated base class method compile fails

I am attempting to call a templated base class method through a derived class. This is my code struct base { template<typename t> void baseMethod(t s) { std::cout << s; } }; struct der : public base { }; int main() { der d; d.<int>(baseMethod(12)); } The compilation fails and states main.cpp: In function 'int main()': main.cpp:25:5: e

调用模板化的基类方法编译失败

我试图通过派生类调用模板化的基类方法。 这是我的代码 struct base { template<typename t> void baseMethod(t s) { std::cout << s; } }; struct der : public base { }; int main() { der d; d.<int>(baseMethod(12)); } 编译失败并指出 main.cpp:在函数'int main()'中:main.cpp:25:5:error:expected'unqualified-id before'<'token

Unresolved reference when using inheritance

How can I get the template definition into a seperate header files? My code compiles when it is included in a single main.cpp. maip.cpp #include <windows.h> #include <tchar.h> template<class T1, class T2> class Base { public: virtual ~Base() {} virtual T1 f1(); virtual T2 f2(); }; template<class T1, class T2> T1 Base<T1, T2>::f1() {return T1();} te

使用继承时未解决的引用

我怎样才能将模板定义转换为独立的头文件? 我的代码在包含在一个main.cpp中时编译。 maip.cpp #include <windows.h> #include <tchar.h> template<class T1, class T2> class Base { public: virtual ~Base() {} virtual T1 f1(); virtual T2 f2(); }; template<class T1, class T2> T1 Base<T1, T2>::f1() {return T1();} template<class T1, class T2> T2 Base<T1,

stack template doesn't compile push func

I wrote this something-like-stack data structure: template<class T> class Stos { class Element { public: T n; Element* prev; Element(const T& k = 0): n(k), prev(0) {} }; Element* member; Stos(Stos&); public: Stos(const T&); ~Stos(); unsigned int count; T get(); Element* push(const T&); T pop();

堆栈模板不能编译push func

我写了这个类似堆栈的数据结构: template<class T> class Stos { class Element { public: T n; Element* prev; Element(const T& k = 0): n(k), prev(0) {} }; Element* member; Stos(Stos&); public: Stos(const T&); ~Stos(); unsigned int count; T get(); Element* push(const T&); T pop(); void mod(const T&am

How to initialize a vector in C++

Possible Duplicate: C++: Easiest way to initialize an STL vector with hardcoded elements I want to initialize a vector like we do in case of an array. Example int vv[2] = {12, 43}; But when I do it like this, vector<int> v(2) = {34, 23}; OR vector<int> v(2); v = {0, 9}; it gives an error: expected primary-expression before '{' token AND error: expected ',

如何在C ++中初始化一个向量

可能重复: C ++:用硬编码元素初始化STL向量的最简单的方法 我想初始化一个向量,就像我们在数组中的情况一样。 例 int vv[2] = {12, 43}; 但是当我这样做时, vector<int> v(2) = {34, 23}; 要么 vector<int> v(2); v = {0, 9}; 它给出了一个错误: 期望在'{'令牌之前的主表达式 和 错误:预期','或';' '='令牌之前 分别。 使用新的C ++标准(可能需要在

GStreamer C++ on Visual Studio 2010?

Following instructions on http://docs.gstreamer.com/display/GstSDK/Installing+on+Windows to install GStreamer and compile tutorials/examples on Windows 7, for compilation using Visual Studio 2010. After installing the SDKs, I try to compile the "hello world" example... Cannot open include file: 'gst/gst.h': No such file or directory. Odd - the tutorials were supposedly configured

在Visual Studio 2010上的GStreamer C ++?

按照http://docs.gstreamer.com/display/GstSDK/Installing+on+Windows上的说明安装GStreamer并在Windows 7上编译教程/示例,以便使用Visual Studio 2010进行编译。 安装SDK后,我尝试编译“hello world”示例... Cannot open include file: 'gst/gst.h': No such file or directory. 奇怪 - 教程被认为是配置了这些文件的路径。 不过,我们可以手动添加它们... 将C: gstreamer-sdk 0.10 x86 include gstreamer-0.10

Writing GStreamer plugins using Visual Studio 2010

I'm trying to write a Gstreamer plugin in Visual Studio 2010. First, I've downloaded GStreamer package for Windows from http://gstreamer.freedesktop.org/download/. Then, I've added required property sheets and removed the dependency with the Visual Studio runtime as described in http://docs.gstreamer.com/display/GstSDK/Installing+on+Windows. I successfully built some examples fro

使用Visual Studio 2010编写GStreamer插件

我试图在Visual Studio 2010中编写一个Gstreamer插件。 首先,我从http://gstreamer.freedesktop.org/download/下载了用于Windows的GStreamer软件包。 然后,我添加了所需的属性表,并按照http://docs.gstreamer.com/display/GstSDK/Installing+on+Windows中所述,使用Visual Studio运行时删除依赖项。 我成功地从Gstreamer应用程序开发手册中构建了一些示例,所以我认为SDK已正确设置。 现在,我的另一个目标是编写我自