Reputation: 1052
While working on my assignment for data structures today, I came across a few errors I had to address that were very new to me. For example, the following:
struct Node
{
// data and stuff
Node(const T& d = T{}, Node * const p = nullptr,
Node * const n = nullptr, unsigned int f = 0)
: data(d), prev(p), next(n), freq(f) {}
// other stuff
};
This ran perfectly fine in visual studio, but not however in g++. I had to change nullptr to 0, even though visual studio wanted me to use nullptr!
Another incident using the school's compiler gave me the following message:
warning: extended initializer lists only available with -std=c++0x
So naturally I went ahead and added this to my makefile.
This got me wondering, how often will I see errors result from simple differences in compilers, given that I will be writing more complex programs in the future? Is visual studio not backwards compatible with older compilers? Can I change settings? Just looking for general knowledge of things I should be aware of when it comes to using various compilers.
Upvotes: 1
Views: 260
Reputation: 20718
g++
will by default compile in C++03 mode, which was the C++ standard before C++11. To tell g++
that your code is in fact C++11 code, you have to use the -std=c++11
compiler switch. For example:
g++ -std=c++11 -o test test.cc
Upvotes: 3