Is uninitialized local variable the fastest random number generator?

I know the uninitialized local variable is undefined behaviour(UB), and also the value may have trap representations which may affect further operation, but sometimes I want to use the random number only for visual representation and will not further use them in other part of program, for example, set something with random color in a visual effect, for example: void updateEffect(){ for(int i

未初始化的局部变量是最快的随机数生成器吗?

我知道未初始化的局部变量是未定义的行为(UB),并且该值可能具有可能影响进一步操作的陷阱表示,但有时我想仅将该随机数用于视觉表示,并且不会在其他部分进一步使用它们程序,例如,用随机颜色设置视觉效果,例如: void updateEffect(){ for(int i=0;i<1000;i++){ int r; int g; int b; star[i].setColor(r%255,g%255,b%255); bool isVisible; star[i].setVisible(i

Get list of source files (and locations) from binary

I'm working in a linux distro. I'm writing a C/C++ program that requires a list of source files that a binary (executable) was compiled with. I compiled the binary using GCC with the -g flag, of course. Using gdb I found out the format of the binary is DWARF2: (gdb) info source Current source file is src/main.cpp Compilation directory is /path/to/source Located in /path/to/source/src/

从二进制文件获取源文件(和位置)列表

我正在一个Linux发行版中工作。 我正在编写一个C / C ++程序,它需要编译一个二进制文件(可执行文件)的源文件列表。 当然,我使用带有-g标志的GCC编译二进制文件。 使用gdb我发现二进制文件的格式是DWARF2: (gdb) info source Current source file is src/main.cpp Compilation directory is /path/to/source Located in /path/to/source/src/main.cpp Contains 43 lines. Source language is c++. Compiled with DWARF 2

Should C++ namespace aliasing be used in header files?

It's considered bad practice to employ using namespace in C++ headers. Is it similarly a bad idea to use namespace aliasing in a header, and each implementation file should declare the aliases it wishes to use? Since headers are the places you tend to use fully specified names (since we don't use namespaces in headers), aliases would be useful but they would still propagate though your

应该在头文件中使用C ++名称空间别名?

在C ++头文件中using namespace被认为是不好的做法。 在标题中使用名称空间别名同样是一个坏主意,每个实现文件都应该声明它希望使用的别名? 由于标题是你倾向于使用完全指定名称的地方(因为我们不在标题中使用名称空间),所以别名会很有用,但是当#included时它们仍然会通过源传播。 这里最好的做法是什么? 命名空间别名的范围是什么? 如果您将名称空间别名放入您的头文件中,则此别名将成为您的(公共)API的一部

Storing and printing 10+ digit integer in c++

I'm using cout to print digits to the console. I am also storing values of up to 13+billion as a digit and doing computations on it. What data type should I use? When I do the following: int a = 6800000000; cout << a; It prints -1789934592. thanks. long long最多可以容纳9223372036854775807.如果你需要更大的话,可以使用类似gmp东西。 Use int64_t to guarantee you won't overflo

在c ++中存储和打印10+数字整数

我正在使用cout将数字打印到控制台。 我还将一个数字的值高达13亿以上,并对其进行计算。 我应该使用哪种数据类型? 当我做到以下几点时: int a = 6800000000; cout << a; 它打印-1789934592。 谢谢。 long long最多可以容纳9223372036854775807.如果你需要更大的话,可以使用类似gmp东西。 使用int64_t来保证你不会溢出。 它可从stdint.h获得。 请注意, int64_t和long long都包含在C99和C ++ 0x中,但不

What are С++ temporaries?

I was reading the constant chapter in Eckel and got mixed up in the part where Temporaries were explained . What I could get was that when we pass the reference to a function , the compiler creates a temporary which is a const object and so we can't modify it even if we pass a reference as f(int &a){} Now I tried to look at some other references for Temporaries online and got stuck up

什么是С++临时对象?

我正在阅读埃克尔的常规章节,并在临时解释部分混淆了。 我可以得到的是,当我们将引用传递给一个函数时,编译器会创建一个临时对象,因此即使我们将引用作为参数传递,我们也不能修改它 f(int &a){} 现在我试着在网上查看一些其他的临时参考文献,并坚持下去 http://publib.boulder.ibm.com/infocenter/lnxpcomp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8l.doc%2Flanguage%2Fref%2Fcplr382.htm和 C ++中所有的临时

C++ Contiguous Sequence Concept

The C++ standard library provides a variety of "Concepts" which are used to specify an interface for container objects. For example, std::vector implements the Container , Sequence , RandomAccessContainer , and ReversibleContainer concepts. Is there a Concept, specified either in C++03 or C++11, that describes a Sequence which guarantees contiguous memory between elements, so that:

C ++连续序列概念

C ++标准库提供了多种用于为容器对象指定接口的“概念”。 例如, std::vector实现了Container , Sequence , RandomAccessContainer和ReversibleContainer概念。 是否有一个概念,在C ++ 03或C ++ 11中指定,它描述了保证元素之间连续内存的Sequence ,以便: static_cast<void*>(&some_sequence[N]) == static_cast<void*>(&some_sequence[0] + N)> 这将是一个有用的概念,因为它告诉你是否可以

Visual Studio 2012 "Smart" Indentation Customization

I am using Visual Studio 2012 and have Smart indentation turned on1 for C++ files.2 I would like to customize Smart indentation's behavior so that it formats the code I enter so that it complies with my company's coding style. How can I customize all the minute aspects of how Smart indentation behaves? For example, when I enter this code, Smart indentation formats it exactly like this

Visual Studio 2012“智能”缩进自定义

我正在使用Visual Studio 2012,并为C ++文件启用了智能缩进功能.1我想定制智能缩进的行为,以便对输入的代码进行格式化,以符合我公司的编码风格。 我如何定制智能缩进行为的所有微小方面? 例如,当我输入此代码时,智能缩进格式如下所示: #include <cstdlib> #include <string> using namespace std; struct Foo { const string mA; const int mB; const string mC; Foo(const string&

How to write a variadic method which replaces chained method calls?

I am working on a recursive map class called group_by which models the SQL namesake. For example, gb is a group_by object which will store pointers to foo grouped by std::string , int , and char key types, in that order. group_by<foo,std::string,int,char> gb; group_by provides an at( I const& key ) accessor method which can be used to look inside current level map. Chaining at() c

如何编写替代链式方法调用的可变参数方法?

我正在研究一个名为group_by的递归映射类,它对SQL同名进行建模。 例如,gb是一个group_by对象,它将以std::string , int和char键类型的顺序存储指向foo指针。 group_by<foo,std::string,int,char> gb; group_by提供了一个at( I const& key )访问器方法,可用于查看当前级别映射。 链接at()调用检索更深的地图工作正常。 auto& v = gb.at( k1 ).at( k2 ).at( k3 ).get_vec(); 问题 我想创建一个名为at_

Inheriting Template class or composition errors

This question already has an answer here: C++ undefined reference to template class method [duplicate] 2 answers Why do I get “unresolved external symbol” errors when using templates? [duplicate] 3 answers

继承模板类或组合错误

这个问题在这里已经有了答案: C ++未定义的引用模板类方法[复制] 2个答案 为什么在使用模板时会出现“未解析的外部符号”错误? [重复] 3个答案

inheritance composite classes in c++

I intend this question to be a more generalized question relating to my question found at the following link: Solving design involving multiple inheritance and composite classes in c++ I am working with data sets related to Galaxies. The data about each galaxy will contain information about a galaxie's solar systems, each solar systems planets and each planets moons. The Composite Requ

在c ++中继承复合类

我打算这个问题是一个更广义的问题,与我在以下链接中发现的问题有关: 在c ++中解决涉及多重继承和复合类的设计 我正在处理与星系相关的数据集。 关于每个星系的数据将包含关于星系的太阳系,每个太阳系行星和每个行星卫星的信息。 综合要求: 仅凭这一点,我想我需要使用复合类设计,为星系,太阳系,行星和卫星创建一个类。 星系类将包含成员容器变量,其中包含指向太阳系,行星和卫星的指针,以及适合这些容器变量