In C++11 it is possible to make a public member of a private base class accessible to the outside (public) with a using declaration. For example class A { private: int i = 2; public: void f() { i = 3; } friend bool operator==(const A& l, const A& r) { return l.i == r.i; } }; class B : private A { public: using A::f; }; int main() { B b, b2; b.f(); } bf() is p
在C ++ 11中,可以using声明使外部(公共)的公共成员可以访问私有基类。 例如 class A { private: int i = 2; public: void f() { i = 3; } friend bool operator==(const A& l, const A& r) { return l.i == r.i; } }; class B : private A { public: using A::f; }; int main() { B b, b2; b.f(); } bf()是可能的,因为在B的定义中using A::f 。 是否有可能写一个类似的声明,这将使
I am currently considering the implementation of a single linked list with the aid of unique_ptrs. Despite the problem of a possible stack overflow due to the recursive call of the destructors (see Stack overflow with unique_ptr linked list), I came across the following problem: Assume, we have the following implementation of the linked list struct node { node (void) : val(0), next(nullptr) {
我目前正在考虑在unique_ptrs的帮助下实施单个链表。 尽管由于析构函数的递归调用而导致堆栈溢出的问题(请参见使用unique_ptr链表的堆栈溢出),但我遇到了以下问题:假设我们有以下链接列表的实现 struct node { node (void) : val(0), next(nullptr) {} int val; std::unique_ptr<node> next; }; 我们已经根据我们的初步清单 int main (int argc, char* argv[]) { node HEAD; HEAD.val = 0; auto ptr =
How can a separate loop affect the performance of an independent earlier loop? My first loop reads some large text files and counts the lines/rows. After a malloc, the second loop populates the allocated matrix. If the second loop is commented out, the first loop takes 1.5 sec. However, compiling WITH the second loop slows down the first loop, which now takes 30-40 seconds! In other words
单独的循环如何影响独立早期循环的性能? 我的第一个循环读取一些大文本文件并计算行/行数。 在malloc之后,第二个循环填充分配的矩阵。 如果第二个循环被注释掉,则第一个循环需要1.5秒。 但是,编译第二个循环会减慢第一个循环,现在需要30-40秒! 换句话说:第二个循环以某种方式减慢了第一个循环。 我试图改变范围,更改编译器,更改编译器标志,更改循环本身,将所有内容放入main(),使用boost :: iostream,甚
I'm trying to configure clang-format so that usually braces will start on their own line: void func() { if (...) { printf("Ta Dan"); } } But I want it to be so when braces are empty, it will be kept in a single line. (Mainly used for ctors): Bar::Bar(int val): _val(val) {} currently it will look like this: Bar::Bar(int val): _val(val) { } Any ideas? (Edite
我正在尝试配置clang格式,以便通常使用大括号从自己的行开始: void func() { if (...) { printf("Ta Dan"); } } 但是,当大括号是空的时候,我希望它是这样,它将被保存在一行中。 (主要用于ctors): Bar::Bar(int val): _val(val) {} 目前它看起来像这样: Bar::Bar(int val): _val(val) { } 有任何想法吗? (编辑使情况更清楚) 我使用了“AllowShortFunctionsOnASingleLine”:true
I am trying to write a class with my own cast operators but I am having issues with multiple operator= s I managed to reproduce the issue with the small code below #include <string> class X { public: operator const char*() const { return "a"; } operator std::string() { return "c"; } }; void func( ) { X x; std::string s = ""; s = x; } I understand that std::basic_
我正在尝试用自己的演员操作员编写一个类,但我遇到了多个operator= s的问题 我设法用下面的小代码重现了这个问题 #include <string> class X { public: operator const char*() const { return "a"; } operator std::string() { return "c"; } }; void func( ) { X x; std::string s = ""; s = x; } 我明白, std::basic_string有多个赋值运算符,这就是编译器感到困惑的原因。 如果我删除
I'm using GCC 4.9 with GCOV to get code and branch coverage. However, the results for branch coverage are utterly useless for my C++ code. It seems GCC inlines templates despite using all -fno-*-inline flags I know of. Here is a small example application that illustrates the problem: #include <string> #include <iostream> using namespace std; int main() { string foo; foo
我使用GCC 4.9和GCOV来获取代码和分支机构覆盖范围。 然而,分支覆盖的结果对我的C ++代码来说完全没有用处。 尽管使用了我所知的所有-fno-*-inline标志,看起来GCC内联了模板。 下面是一个小例子应用程序来说明问题: #include <string> #include <iostream> using namespace std; int main() { string foo; foo = "abc"; cout << foo << endl; } 我使用g++ -O0 -fno-inline -fno-inline
Consider this code: int x = 0; template<int& I> struct SR {}; template<int* I> struct SP {}; SR<(x)> sr; SP<&(x)> sp; int main(void) { } clang++ 3.8.0 complains: main.cpp:10:5: error: non-type template argument does not refer to any declaration SP<&(x)> sp; ^~~ main.cpp:6:15: note: template parameter is declared here template<int* I>
考虑这个代码: int x = 0; template<int& I> struct SR {}; template<int* I> struct SP {}; SR<(x)> sr; SP<&(x)> sp; int main(void) { } 铿锵声++ 3.8.0抱怨: main.cpp:10:5: error: non-type template argument does not refer to any declaration SP<&(x)> sp; ^~~ main.cpp:6:15: note: template parameter is declared here template<int* I>
This is a follow-up of these questions. Consider the following code: struct A { private: A* const& this_ref{this}; }; int main() { A a{}; (void)a; } If compiled with the -Wextra , both GCC v6.2 and clang v3.9 show a warning. Anyway, with the slightly modified version shown below they behave differently: struct A { A* const& this_ref{this}; }; int main() { A a{
这是这些问题的后续行动。 考虑下面的代码: struct A { private: A* const& this_ref{this}; }; int main() { A a{}; (void)a; } 如果使用-Wextra编译,则GCC v6.2和clang v3.9均会显示警告。 无论如何,在下面显示的稍微修改后的版本中,它们的行为不同: struct A { A* const& this_ref{this}; }; int main() { A a{}; (void)a; } 在这种情况下,GCC不会给出任何警告,clang会给出
Ours is a PowerPC based embedded system running Linux. We are encountering a random SIGILL crash which is seen for wide variety of applications. The root-cause for the crash is zeroing out of the instruction to be executed. This indicates corruption of the text segment residing in memory. As the text segment is loaded read-only, the application cannot corrupt it. So I am suspecting some comm
我们是一个运行Linux的基于PowerPC的嵌入式系统。 我们遇到了随机SIGILL崩溃,这种崩溃在各种应用程序中都可见。 崩溃的根本原因是将要执行的指令置零。 这表示驻留在内存中的文本段的损坏。 由于文本段是只读的,因此应用程序无法对其进行破坏。 所以我怀疑一些共同的子系统(DMA?)造成这种腐败。 由于问题需要数天才能重现(由于SIGILL而导致崩溃),因此调查变得越来越困难。 因此,首先我想知道是否以及何时应用程
I have some C++11 code that fails to compile on Visual Studio 2015 (Update 2), but compiles without error on both Clang and GCC. Therefore, I am suspecting a compiler bug in Visual Studio, but maybe my code is somehow ill-formed. My real class BaseUnit is a template wrapper class over a double value, taking care about the physical dimensions of quantities (expressed as SI units m, kg, s, K).
我有一些C ++ 11代码无法在Visual Studio 2015(更新2)上编译,但在Clang和GCC上编译时没有错误。 因此,我怀疑Visual Studio中有一个编译器错误,但也许我的代码有些不合格。 我的真实类BaseUnit是一个超过double值的模板包装类,关注数量的物理尺寸(表示为SI单位m,kg,s,K)。 例如,速度与时间模板实例的相乘会自动给出一个距离实例。 当前实现乘以标量的问题会出现问题。 我尽可能简化班级,以展示问题。 #include