i am testing std::move with this simple example
but when i tried to compile this code, the error occur
#include <utility> // std::move
#include <iostream> // std::cout
#include <vector> // std::vector
#include <string> // std::string
int main () {
std::string foo = "foo-string";
std::string bar = "bar-string";
std::vector<std::string> myvector;
myvector.push_back (foo); // copies
myvector.push_back (std::move(bar)); // moves
std::cout << "myvector contains:";
for (std::string& x:myvector) std::cout << ' ' << x;
std::cout << '\n';
return 0;
}
but the console window in eclipse seems to say that compile is successful like below
So i tried to compile with console command and not eclipse to check what is correct
g++ -D__GXX_EXPERIMENTAL_CXX0X__ -std=c++11 test.cpp
that was successful and working.
what is problem with eclipse?
i am using eclipse version 3.8
I guess that gcc
being invoked by Eclipse doesn't receive -std=c++11
argument. If you have a modern CDT check this page: http://wiki.eclipse.org/CDT/User/NewIn83#Toolchains If not, do as @JoshKelley suggests
You're getting errors from Eclipse CDT's Code Analysis, not from your compiler. Code Analysis can be useful, but it can be finicky to set up, and because it involves Eclipse doing its own (limited) C++ parse, it doesn't always agree with the real compiler. (The "Semantic error" in the "Type" column is a giveaway that it's a Code Analysis error. Actual compiler errors are listed as "C/C++ Errors.")
Code Analysis errors are harmless - as you saw, they don't affect compilation. To make Code Analysis work, Eclipse does "discovery" - it invokes GCC itself and parses the output to determine stuff like preprocessor defines, include paths, etc. There's a good chance your Eclipse isn't enabling C++11 when it does discovery. Fixing it depends somewhat on your system and version of Eclipse; here's how I fixed it:
-std=c++11
to the end of the "command to get compiler specs."In the newest Eclipse, if you're letting Eclipse manage your C++ settings instead of writing your own makefiles, then as @user3159253 says, you can use the toolchain support instead of manually editing compiler settings.
Here are a couple of other things to try.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With