S
Single Stage to Orbit
I get the following error when trying to compile with GNU G++ 4.5.3, how
can I change it to get it to build?
$ g++ -std=gnu++0x threads1.cpp -o threads1
threads1.cpp: In function ‘int main()’:
threads1.cpp:18:57: error: expected ‘)’ before ‘;’ token
threads1.cpp:21:15: error: expected initializer before ‘:’ token
threads1.cpp:27:2: error: expected primary-expression before ‘return’
threads1.cpp:27:2: error: expected ‘)’ before ‘return’
#include <iostream>
#include <vector>
#include <thread>
#include <functional>
void func(int& counter)
{
for (int i = 0; i < 10000; ++i)
++counter;
}
int main()
{
int counter = 0;
std::vector<std::thread> threads;
for (int i = 0; i < 10; ++i)
{
threads.push_back(std::thread{func, std::ref(counter)};
}
for (auto& t : threads)
{
t.join();
}
std::cout << "Result = " << counter << '\n';
return 0;
}
can I change it to get it to build?
$ g++ -std=gnu++0x threads1.cpp -o threads1
threads1.cpp: In function ‘int main()’:
threads1.cpp:18:57: error: expected ‘)’ before ‘;’ token
threads1.cpp:21:15: error: expected initializer before ‘:’ token
threads1.cpp:27:2: error: expected primary-expression before ‘return’
threads1.cpp:27:2: error: expected ‘)’ before ‘return’
#include <iostream>
#include <vector>
#include <thread>
#include <functional>
void func(int& counter)
{
for (int i = 0; i < 10000; ++i)
++counter;
}
int main()
{
int counter = 0;
std::vector<std::thread> threads;
for (int i = 0; i < 10; ++i)
{
threads.push_back(std::thread{func, std::ref(counter)};
}
for (auto& t : threads)
{
t.join();
}
std::cout << "Result = " << counter << '\n';
return 0;
}