c++14

Why does gcc warn about calling a non-trivial move assignment operator with std::tuple and virtual inheritance?

扶醉桌前 提交于 2020-12-23 03:31:44
问题 In the following example gcc 7 gives a warning: defaulted move assignment for 'B' calls a non-trivial move assignment operator for virtual base 'A' [-Wvirtual-move-assign] if I create an std::tuple<B> object. Clang 5 doesn't report any problems. Also the problem goes away if vector is removed from Base . Example. #include <tuple> #include <vector> class Base { public: virtual ~Base(); std::vector<int> v; }; class A : public Base { }; class B : public virtual A { }; int main() { B *b = new B;

Why does gcc warn about calling a non-trivial move assignment operator with std::tuple and virtual inheritance?

徘徊边缘 提交于 2020-12-23 03:29:48
问题 In the following example gcc 7 gives a warning: defaulted move assignment for 'B' calls a non-trivial move assignment operator for virtual base 'A' [-Wvirtual-move-assign] if I create an std::tuple<B> object. Clang 5 doesn't report any problems. Also the problem goes away if vector is removed from Base . Example. #include <tuple> #include <vector> class Base { public: virtual ~Base(); std::vector<int> v; }; class A : public Base { }; class B : public virtual A { }; int main() { B *b = new B;

Why does gcc warn about calling a non-trivial move assignment operator with std::tuple and virtual inheritance?

蹲街弑〆低调 提交于 2020-12-23 03:27:01
问题 In the following example gcc 7 gives a warning: defaulted move assignment for 'B' calls a non-trivial move assignment operator for virtual base 'A' [-Wvirtual-move-assign] if I create an std::tuple<B> object. Clang 5 doesn't report any problems. Also the problem goes away if vector is removed from Base . Example. #include <tuple> #include <vector> class Base { public: virtual ~Base(); std::vector<int> v; }; class A : public Base { }; class B : public virtual A { }; int main() { B *b = new B;

Calling Another Function in a Recusive Function results in error. Why?

时间秒杀一切 提交于 2020-12-15 19:17:52
问题 I've two functions fun() and fun2(); fun() calls itself while incrementing the global variable a=0 and terminates if a==5. But if I call another function called fun2() which basically returns and do nothing, then Build Error happens. Why? I'm just experimenting with recursion and I got this error. #include<iostream> using namespace std; int a = 0; void fun() { if (a == 5) return; a++; fun(); fun2(); //This is where the trouble happens } void fun2() { return; } int main() { fun(); return 0; }

Calling Another Function in a Recusive Function results in error. Why?

我们两清 提交于 2020-12-15 19:17:13
问题 I've two functions fun() and fun2(); fun() calls itself while incrementing the global variable a=0 and terminates if a==5. But if I call another function called fun2() which basically returns and do nothing, then Build Error happens. Why? I'm just experimenting with recursion and I got this error. #include<iostream> using namespace std; int a = 0; void fun() { if (a == 5) return; a++; fun(); fun2(); //This is where the trouble happens } void fun2() { return; } int main() { fun(); return 0; }

std::filesystem and std::experimental::filesystem problem in different compilers

余生长醉 提交于 2020-12-15 06:47:30
问题 I am writing a library (just for learning) which utilizes std::filesystem. It works fine on MSVC however by default LTS releases of Linux like Ubuntu ships with GCC 6.x and clang in the official repository is 3.8 which doesn't have std::filesystem instead I have to use std::experimental::filesystem. How may I workaround this problem so that I can support GCC 6, GCC 8+ (where std::filesystem works), Clang 3.8, latest Clang and MSVC? I am using CMAKE as my build system 回答1: Conditional

std::filesystem and std::experimental::filesystem problem in different compilers

大兔子大兔子 提交于 2020-12-15 06:47:09
问题 I am writing a library (just for learning) which utilizes std::filesystem. It works fine on MSVC however by default LTS releases of Linux like Ubuntu ships with GCC 6.x and clang in the official repository is 3.8 which doesn't have std::filesystem instead I have to use std::experimental::filesystem. How may I workaround this problem so that I can support GCC 6, GCC 8+ (where std::filesystem works), Clang 3.8, latest Clang and MSVC? I am using CMAKE as my build system 回答1: Conditional

Proper way to define type (typedef vs #define)

空扰寡人 提交于 2020-12-06 04:03:03
问题 Which of these methods is more secure for defining variable types? I know that we all frown when we see #defines, but it seems to work just as well as typedef here: Is there an advantage one way or the other, and if so what might it be? Method One: #include <iostream> #define byte unsigned char int main() { byte testByte = 'A'; std::cout << testByte << std::endl; return 0; } Method Two: #include <iostream> int main() { typedef unsigned char byte; byte testByte = 'A'; std::cout << testByte <<

Proper way to define type (typedef vs #define)

空扰寡人 提交于 2020-12-06 04:03:02
问题 Which of these methods is more secure for defining variable types? I know that we all frown when we see #defines, but it seems to work just as well as typedef here: Is there an advantage one way or the other, and if so what might it be? Method One: #include <iostream> #define byte unsigned char int main() { byte testByte = 'A'; std::cout << testByte << std::endl; return 0; } Method Two: #include <iostream> int main() { typedef unsigned char byte; byte testByte = 'A'; std::cout << testByte <<

Proper way to define type (typedef vs #define)

心已入冬 提交于 2020-12-06 04:02:29
问题 Which of these methods is more secure for defining variable types? I know that we all frown when we see #defines, but it seems to work just as well as typedef here: Is there an advantage one way or the other, and if so what might it be? Method One: #include <iostream> #define byte unsigned char int main() { byte testByte = 'A'; std::cout << testByte << std::endl; return 0; } Method Two: #include <iostream> int main() { typedef unsigned char byte; byte testByte = 'A'; std::cout << testByte <<