Possible Duplicate: What does the explicit keyword in C++ mean? I do not understand the following. If I have: class Stack{ explicit Stack(int size); } without the keyword explicit I would be allowed to do: Stack s; s = 40; Why would I be allowed to do the above if explicit wasn't provided?? Is it because this is stack-allocation (no constructor) and C++ allows anything to be ass
可能重复: C ++中的显式关键字是什么意思? 我不明白以下内容。 如果我有: class Stack{ explicit Stack(int size); } 没有explicit的关键字我将被允许执行: Stack s; s = 40; 如果显式不提供,为什么我会被允许执行上述操作? 是因为这是堆栈分配(没有构造函数),并且C ++允许将任何东西分配给变量,除非使用了explicit ? 这条线 s = 40; 相当于 s.operator = (40); 它试图匹配默认的operator = (con
Possible Duplicate: What does the explicit keyword in C++ mean? what does the keyword explicit mean? C++ constructors that have just one parameter automatically perform implicit type conversion. For example, if you pass an int when the constructor expects a string pointer parameter, the compiler will add the code it must have to convert the int to a string pointer. However, you might not
可能重复: C ++中的显式关键字是什么意思? 关键字explicit是什么意思? 只有一个参数的C ++构造函数会自动执行隐式类型转换。 例如,如果在构造函数需要一个字符串指针参数时传递一个int,编译器将添加它必须具有的代码以将int转换为一个字符串指针。 但是,您可能并不总是需要这种自动行为。 您可以将显式添加到构造函数声明以防止隐式转换。 这会强制代码使用正确类型的参数,或者将参数强制转换为正确的类型。
Possible Duplicate: What does the explicit keyword in C++ mean? explicit CImg(const char *const filename):_width(0),_height(0),_depth(0),_spectrum(0),_is_shared(false),_data(0) { assign(filename); } what's the difference with or without it? It's use to decorate constructors; a constructor so decorated cannot be used by the compiler for implicit conversions. C++ allows up to one
可能重复: C ++中的显式关键字是什么意思? explicit CImg(const char *const filename):_width(0),_height(0),_depth(0),_spectrum(0),_is_shared(false),_data(0) { assign(filename); } 有或没有它有什么区别? 用来装饰构造函数; 一个如此修饰的构造函数不能被编译器用于隐式转换。 C ++允许最多一个用户提供的转换,其中“用户提供的”意思是“通过类构造函数”,例如: class circle { circle( const int r )
This question already has an answer here: What does the explicit keyword mean? 11 answers inline is necessary if you define a function in a header, but not in a class definition. It allows the function to be defined in multiple translation units (ie when including the header from multiple source files). The purpose is to allow the compiler to inline calls to the function - many compilers r
这个问题在这里已经有了答案: 显式关键字是什么意思? 11个答案 如果您在头中定义函数,而不是在类定义中定义函数,则inline是必需的。 它允许在多个翻译单元中定义该功能(即,当包含来自多个源文件的标题时)。 目的是为了让编译器内联调用函数 - 许多编译器要求定义在翻译单元中可用,才能做到这一点。 在这种情况下,它是毫无意义的:在类定义中定义的函数隐式内联。 explicit意味着构造函数不能用于隐式类型转
Possible Duplicate: What does the explicit keyword in C++ mean? Is there a reason to use the explicit keyword for a function that doesn't take any arguments? Does it have any effect? I'm wondering because I just came across the line explicit char_separator() near the end of the page documenting boost::char_separator ( http://www.boost.org/doc/libs/1_47_0/libs/tokenizer/char_sepa
可能重复: C ++中的显式关键字是什么意思? 有没有理由使用explicit关键字的功能,不接受任何参数? 它有什么作用? 我想知道,因为我刚刚碰到线 explicit char_separator() 靠近记录boost :: char_separator的页面末尾(http://www.boost.org/doc/libs/1_47_0/libs/tokenizer/char_separator.htm),但在此处不再进行解释。 阅读成员的解释: explicit char_separator(const Char* dropped_delims,
Is there some way to force C++ compilers to perform name lookup for a given symbol during template instantiation (and not before)? Given the following code: template <class T> auto wrapper( T t ) -> decltype( f( t ) ) { return f( t ); } unsigned char f( int x ) { return x % 256; } unsigned char f( unsigned char x ) { return x; } int main( int, char ** ) { auto x = wrapper( 3
有没有办法强制C ++编译器在模板实例化(而不是之前)中为给定的符号执行名称查找? 给出以下代码: template <class T> auto wrapper( T t ) -> decltype( f( t ) ) { return f( t ); } unsigned char f( int x ) { return x % 256; } unsigned char f( unsigned char x ) { return x; } int main( int, char ** ) { auto x = wrapper( 3100 ); return 0; } 有什么我可以做的(除了将f的定义移到顶
short -- Is it possible to build a external binary/library out of a project with CMake, when the binary/library only has a makefile given? So you have your own project, a bunch of CMakeLists.txt in your src-tree and this external library with its source-files. Your sources depend on this library and some binaries/libraries want to link against it. How would one compile this external library i
简短 - 当二进制文件/库只有一个生成文件给出时,是否有可能使用CMake从项目中构建外部二进制/库? 所以你有自己的项目,在你的src-tree中有一堆CMakeLists.txt,并且这个外部库有它的源文件。 你的源代码取决于这个库,一些二进制文件/库希望链接它。 如果只有makefile或Visual Studio项目文件而没有给定CMakeLists.txt,那么如何编译此外部库? 有没有机会调用配置/制作CMake? 或者在Windows下使用VS进行批量编译? 还
I have 2 pointers which points to two 20 member arrays. My arrays contains complex numbers. I want to make element by element division for that complex numbers that is why I need to separate numbers to real and imaginary parts. I tried the following code but it gives error. #include <complex> complex *a; complex *b; complex array1[20]; complex array2[20]; a = &a
我有2个指向两个20个成员数组的指针。 我的数组包含复数。 我想通过元素除法为复杂数字进行元素分解,这就是为什么我需要将数字分成实部和虚部。 我尝试了下面的代码,但它给出了错误。 #include <complex> complex *a; complex *b; complex array1[20]; complex array2[20]; a = &array1; b = &array2; int i=0; for (i=0;i<=19;i++) { real_part_array1[i]
Is it possible to print sum of a vector of doubles in while debugging in GDB? I know the values of a vector can be printed by *(vec._M_impl._M_start)@N, but I just want summation of huge array what can be done? One solution is to write C++ function and call it in GDB. Any other easier solution? It can be done via gdb script, but I think writing c++ function and calling it is better solution.
在GDB中调试时可以打印双精度矢量的和吗? 我知道矢量的值可以通过*(vec._M_impl._M_start)@N打印出来,但是我只想对大数组进行求和操作。 一种解决方案是编写C ++函数并在GDB中调用它。 其他更简单的解决方案 它可以通过gdb脚本完成,但我认为编写c ++函数并调用它是更好的解决方案。 尽管如此,脚本(通过使用STL支持工具并修改它创建)如下所示: define pvecsum set $sum = 0 set $size = $arg0._M_impl._M
The man pages for htonl() seem to suggest that you can only use it for up to 32 bit values. (In reality, ntohl() is defined for unsigned long, which on my platform is 32 bits. I suppose if the unsigned long were 8 bytes, it would work for 64 bit ints). My problem is that I need to convert 64 bit integers (in my case, this is an unsigned long long) from big endian to little endian. Right now,
htonl()的手册页似乎暗示你最多只能使用它32位的值。 (实际上, ntohl()被定义为unsigned long,在我的平台上是32位。我想如果unsigned long是8个字节,它可以用于64位int)。 我的问题是我需要从大端到小端转换64位整数(在我的情况下,这是一个无符号长整数)。 现在,我需要做具体的转换。 但是如果函数(如ntohl() )不能转换我的64位值(如果目标平台是WAS大端ntohl()它会更好。 (我宁愿避免添加我自己的预处理器魔