0

I have an unfortunate problem. My GCC 4.6.3 compiler refuses to compile my move constructor. Exchanging line 6 in the example with "MemoryBlock(const MemoryBlock & other)" would make it compile, but not using the below move constructor declaration. Seems like the compiler does not know C+11, even though it should using 4.6.3. Right?

#include <cstddef> class MemoryBlock { public: MemoryBlock(MemoryBlock && other) //<----------- RAD 6. { } private: size_t _length; // The length of the resource. int* _data; // The resource. }; int main() { } 

Compiler output:

prog.cpp:6:28: error: expected ‘,’ or ‘...’ before ‘&&’ token

prog.cpp:6:36: error: invalid constructor; you probably meant ‘MemoryBlock (const MemoryBlock&)’

make: * [slask] Error 1

GCC version:

g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 (Kör från labbsal i skolan)

makefile:

%.out: %.cpp g++ -g -W -Wall -std=c++0x $*.cpp -o $*.out; 
6
  • 3
    Works fine on my GCC 4.6.3. Make sure you're actually using the right version; check directly on the command line without makefile perhaps. Commented Sep 30, 2013 at 12:54
  • I did verify my version (g++ --version) and its correct. However, you are right, it works. The problem seem to lie within my makefile. Thanks alot! My makefile seemed so simple that I didn't really consider it an issue. Any idea what could be the problem using this makefile? Commented Sep 30, 2013 at 12:58
  • 3
    Your makefile may not be using the rule you specified, but the default rule. Commented Sep 30, 2013 at 13:00
  • You can greatly simplify the makefile for small code samples by setting CXXFLAGS and letting the default rules do their job. Commented Sep 30, 2013 at 13:01
  • 1
    In fact, the more I look at it, the more it seems that Everything Is Wrong with that makefile. Maybe pick up a Makefile tutorial and work though it slowly, step-by-step. Especially substitution rules and magic variables should be double-checked. Commented Sep 30, 2013 at 13:01

1 Answer 1

1

Try -std=c++11 instead of -std=c++0x. While your compiler knows the usage, the -std=c++0x "turns off" those new rules.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.