g++

Atomic struct containing pointer

隐身守侯 提交于 2020-08-19 12:20:52
问题 #include <atomic> #include <iostream> using namespace std; struct Simple{ int a = 0; int b = 0; }; struct WithPointer{ int *a = nullptr; int b = 0; }; int main(int argc, char const *argv[]) { atomic<Simple> simple; cout<<simple.is_lock_free()<<"\n"; atomic<Simple*> simple_p; cout<<simple_p.is_lock_free()<<"\n"; atomic<WithPointer> with_pointer; cout<<with_pointer.is_lock_free()<<"\n"; return 0; } This example works fine for the Simple struct but not for the WithPointer struct. I get the

Atomic struct containing pointer

拟墨画扇 提交于 2020-08-19 12:12:09
问题 #include <atomic> #include <iostream> using namespace std; struct Simple{ int a = 0; int b = 0; }; struct WithPointer{ int *a = nullptr; int b = 0; }; int main(int argc, char const *argv[]) { atomic<Simple> simple; cout<<simple.is_lock_free()<<"\n"; atomic<Simple*> simple_p; cout<<simple_p.is_lock_free()<<"\n"; atomic<WithPointer> with_pointer; cout<<with_pointer.is_lock_free()<<"\n"; return 0; } This example works fine for the Simple struct but not for the WithPointer struct. I get the

Trouble installing CudaSift

流过昼夜 提交于 2020-08-06 04:46:06
问题 I just moved to C++ from Python. I'm using VSCode and I'd like to use the following library: https://github.com/Celebrandil/CudaSift . So I clone the repo, make a build folder inside, cd to the build folder, use: cmake .. then sudo make and finally sudo make install I get the following output in console: After completing these steps, I get a shared library file called 'cudasift'. From what I understand, I must then compile my code, which is the following: #include <iostream> #include <opencv4

Copy constructor chosen over move constructor when returning non-static local object

↘锁芯ラ 提交于 2020-07-29 07:38:48
问题 I used to assume that a class' move constructors would be given priority over its copy constructors, but in the code below it seems that the copy constructor is chosen even though the object should be movable. Do you have any idea why below codes choose copy constructor when foo() returns vector<B> B ? #include <iostream> #include <vector> using namespace std; class B { public: int var_; B(int var) : var_(var) { cout << "I'm normal" << endl; } B(const B& other) { cout << "I'm copy constructor

C++ undefined reference to defined function

江枫思渺然 提交于 2020-07-17 03:19:07
问题 I cannot figure out why this is not working. I will put up all three of my files and possibly someone can tell me why it is throwing this error. I am using g++ to compile the program. Program: #include <iostream> #include "h8.h" using namespace std; int main() { char sentence[MAX_SENTENCE_LENGTH]; char writeTo[] = "output.txt"; int distanceTo,likePosition, length, numWords; cout << "ENTER A SENTENCE! "; cin.getline(sentence, 299); length = strlen(sentence); numWords = wordCount(sentence,

Clang vs G++ lvalue to rvalue conversion

旧城冷巷雨未停 提交于 2020-07-09 11:55:56
问题 The question related to this one. By tracing slt_pair. h and move. h , it's seems that the difference between Clang and G++ is internally. I have tried to simulate the assignment of the object (pair.first) as same as the implementation of std_pair.h , the output is same as Clang output it's reasonable output, but why when using pairs it's changes. #include <iostream> struct Foo { Foo() { std::cout << "default" << std::endl; } Foo(Foo& f2) { std::cout << "non-const" << std::endl; } Foo(const

problems using threads in C++ on windows 10 (using g++ as compiler)

戏子无情 提交于 2020-07-05 10:41:25
问题 I'm trying to create a thread and make it print something to the terminal. I was having some problems so I decided to take this very simple piece of code someone else made, when I compile it I get the errors listed below, but other people online seem to have no problem running this. #include <iostream> #include <thread> using namespace std; void hello_world() { cout << "Hello from thread!\n"; } int main() { thread threadobj1(hello_world); threadobj1.join(); return 0; } The compiler (mingw32

Error: expected constructor, destructor, or type conversion before ';' token?

佐手、 提交于 2020-07-04 10:51:53
问题 I'm trying to compile my code to test a function to read and print a data file, but I get a compiling error that I don't understand - "error: expected constructor, destructor, or type conversion before ';' token". Wall of relevant code-text is below. struct Day { int DayNum; int TempMax; int TempMin; double Precip; int TempRange; }; struct Month { Day Days[31]; int MonthMaxTemp; int MonthMinTemp; double TotalPrecip; int MonthMaxTempRange; int MonthMinTempRange; double AverageMaxTemp; double

Error: expected constructor, destructor, or type conversion before ';' token?

左心房为你撑大大i 提交于 2020-07-04 10:51:34
问题 I'm trying to compile my code to test a function to read and print a data file, but I get a compiling error that I don't understand - "error: expected constructor, destructor, or type conversion before ';' token". Wall of relevant code-text is below. struct Day { int DayNum; int TempMax; int TempMin; double Precip; int TempRange; }; struct Month { Day Days[31]; int MonthMaxTemp; int MonthMinTemp; double TotalPrecip; int MonthMaxTempRange; int MonthMinTempRange; double AverageMaxTemp; double

Error: expected constructor, destructor, or type conversion before ';' token?

China☆狼群 提交于 2020-07-04 10:51:31
问题 I'm trying to compile my code to test a function to read and print a data file, but I get a compiling error that I don't understand - "error: expected constructor, destructor, or type conversion before ';' token". Wall of relevant code-text is below. struct Day { int DayNum; int TempMax; int TempMin; double Precip; int TempRange; }; struct Month { Day Days[31]; int MonthMaxTemp; int MonthMinTemp; double TotalPrecip; int MonthMaxTempRange; int MonthMinTempRange; double AverageMaxTemp; double