A BIG bug of VC++? Why does initializer

The C++11 standard 8.5.4.3 says: "If the initializer list has no elements and T is a class type with a default constructor, the object is value-initialized." struct A { int get() { return i; } private: int i; }; int main() { A a = {}; int n = a.get(); cout << n << endl; // n is a random number rather than 0 return 0; } Is this a bug of VC+

VC ++的一个大错误? 为什么初始化器

C ++ 11标准8.5.4.3说: “如果初始化程序列表中没有元素,并且T是具有默认构造函数的类类型,则该对象将进行值初始化。” struct A { int get() { return i; } private: int i; }; int main() { A a = {}; int n = a.get(); cout << n << endl; // n is a random number rather than 0 return 0; } 这是VC ++的错误吗? 我的VC ++是最新的2012年11月CTP。 8.5p8覆盖了非聚合

C++ Address of lambda objects as parameters to functions

From my experience it seems that either: A lambda expression created inside a function call is destroyed just after the invocation Calling a function that expects a std::function creates a temporary object (std::function) out of the lambda, and that object is destroyed after invocation This behavior can be observed with the following snippet of code: const function<void()>* pointer;

lambda对象的C ++地址作为函数的参数

从我的经验看来,无论是: 在函数调用内部创建的lambda表达式在调用之后被销毁 调用需要std::function会从lambda中创建一个临时对象(std :: function),并且该对象在调用后被销毁 用下面的代码片段可以看到这种行为: const function<void()>* pointer; void a(const function<void()> & f) { pointer = &f; } void b() { (*pointer)(); } int main() { int value = 1; std::cou

SDL2 OpenGL3 How to initialize SDL inside a function

I'm experimenting with the new SDL2 beta and an OpenGL3 context, and I'm having a weird problem: If I run the SDL initialization code in my main() function, it works fine, but I want to have this code in a separete init_sdl() function. If I put the initialization code in a separate init_sdl() function, and call this function from main(), the background color is never drawn, and the pr

SDL2 OpenGL3如何初始化函数中的SDL

我正在尝试新的SDL2测试版和OpenGL3上下文,并且出现了一个奇怪的问题: 如果我在main()函数中运行SDL初始化代码,它可以正常工作,但我希望将此代码放在单独的init_sdl()函数中。 如果我将初始化代码放在一个单独的init_sdl()函数中,并从main()中调用此函数,则从不绘制背景色,程序开始疯狂地占用我系统的所有资源。 有人可以指点我一个SDL在独立函数中初始化的工作示例吗? 我似乎无法找到一个...也许这是不

Decode a video file from memory using libav

Supose I have an entire video file in memory and I want to use libav to decode the whole frames. How should I do it? The point is that I can do it reading directly from a file using avformat_open_input() function but I do need to do it from a file which is stored in memory. My AVIOContext implementation: class AVIOMemContext { public: AVIOMemContext(char* videoData, const int videoLen)

使用libav从内存解码视频文件

Supose我在内存中有一个完整的视频文件,我想用libav来解码整个帧。 我应该怎么做? 关键是我可以使用avformat_open_input()函数直接从文件中读取数据,但我确实需要从存储在内存中的文件中完成。 我的AVIOContext实现: class AVIOMemContext { public: AVIOMemContext(char* videoData, const int videoLen) { // Output buffer bufferSize = 32768; buffer = static_cast<char*&g

Express general monadic interface (like Monad class) in C++

Is it even possible to express a sort of monad" C++ ? I started to write something like this, but stuck: #include <iostream> template <typename a, typename b> struct M; template <typename a, typename b> struct M { virtual M<b>& operator>>( M<b>& (*fn)(M<a> &m, const a &x) ) = 0; }; template <typename a, typename b> str

在C ++中表达一般的monadic接口(如Monad类)

是否甚至有可能表达一种monad“C ++?我开始写这样的东西,但卡住了: #include <iostream> template <typename a, typename b> struct M; template <typename a, typename b> struct M { virtual M<b>& operator>>( M<b>& (*fn)(M<a> &m, const a &x) ) = 0; }; template <typename a, typename b> struct MSome : public M<a> { virtual M

How to access the RGB values in Opencv?

I am confused about the use of number of channels. Which one is correct of the following? // roi is the image matrix for(int i = 0; i < roi.rows; i++) { for(int j = 0; j < roi.cols; j+=roi.channels()) { int b = roi.at<cv::Vec3b>(i,j)[0]; int g = roi.at<cv::Vec3b>(i,j)[1]; int r = roi.at<cv::Vec3b>(i,j)[2]; cout << r <<

如何访问Opencv中的RGB值?

我对使用多个频道感到困惑。 哪一个是正确的以下? // roi is the image matrix for(int i = 0; i < roi.rows; i++) { for(int j = 0; j < roi.cols; j+=roi.channels()) { int b = roi.at<cv::Vec3b>(i,j)[0]; int g = roi.at<cv::Vec3b>(i,j)[1]; int r = roi.at<cv::Vec3b>(i,j)[2]; cout << r << " " << g << " " << b &l

Low level disk operations in Linux for C++

What kind of methods exists in linux for low level disk operations in C++? I am attempting to write my own manager of data on a disk. For example, I would like to create a C++ program in the Linux environment that allocated a certain amount (continuous) on a disk and then freely allows me to read/write to that chunk of data. I don't think I want to use the standard fstream::open because th

Linux for C ++中的低级磁盘操作

在Linux中,C ++中的低级磁盘操作有哪些方法? 我试图在磁盘上写入自己的数据管理器。 例如,我想在Linux环境中创建一个C ++程序,该程序在磁盘上分配一定数量(连续的),然后自由地允许我读取/写入该数据块。 我不认为我想使用标准的fstream::open因为这个文件是由操作系统管理的,我可能没有在磁盘上获得连续的部分。 谢谢。 通常,Linux中用户程序1的“低级”磁盘操作涉及打开磁盘专用设备。 在我的计算机上,这些被称

template template syntax problems with variadic templates

I have a problem with variadic template templates: template <typename T> class A { }; template< template <typename> class T> class B { }; template <template <typename> class T, typename parm> class C { typedef T<parm> type; }; template <typename... types> class D { }; template <template <t

模板模板与可变参数模板的语法问题

我有一个可变参数模板模板的问题: template <typename T> class A { }; template< template <typename> class T> class B { }; template <template <typename> class T, typename parm> class C { typedef T<parm> type; }; template <typename... types> class D { }; template <template <typename...> cla

c++

When I try to use std::distance with a custom iterator under gcc 4.7, it complains about not finding the difference_type . I have sadly no idea why it fails. #include <iterator> class nit { public: typedef int difference_type; }; int main() { const nit test1; std::distance( test1, test1 ); return 0; } gives the error: /usr/include/c++/4.7/bits/stl_iterator_base_funcs.h:114:

C ++

当我尝试在gcc 4.7下使用std::distance与自定义迭代器时,它抱怨找不到difference_type 。 我很遗憾不知道为什么它失败了。 #include <iterator> class nit { public: typedef int difference_type; }; int main() { const nit test1; std::distance( test1, test1 ); return 0; } 给出错误: /usr/include/c++/4.7/bits/stl_iterator_base_funcs.h:114:5: error: no type named 'difference_type'

Why does this constexpr code cause GCC to eat all my RAM?

The following program will call fun 2 ^ (MAXD + 1) times. The maximum recursion depth should never go above MAXD, though (if my thinking is correct). Thus it may take some time to compile, but it should not eat my RAM. #include<iostream> const int MAXD = 20; constexpr int fun(int x, int depth=0){ return depth == MAXD ? x : fun(fun(x + 1, depth + 1) + 1, depth + 1); } int main(){ c

为什么这个constexpr代码会导致GCC吃掉我所有的RAM?

以下程序将调用fun 2 ^(MAXD + 1)次。 尽管(如果我的想法是正确的话),最大递归深度不应该超过MAXD。 因此编译可能需要一些时间,但它不应该吃我的RAM。 #include<iostream> const int MAXD = 20; constexpr int fun(int x, int depth=0){ return depth == MAXD ? x : fun(fun(x + 1, depth + 1) + 1, depth + 1); } int main(){ constexpr int i = fun(1); std::cout << i << std::endl; }