0
votes

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;
1
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.Kerrek SB
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?user2831216
Your makefile may not be using the rule you specified, but the default rule.Kerrek SB
You can greatly simplify the makefile for small code samples by setting CXXFLAGS and letting the default rules do their job.juanchopanza
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.Kerrek SB

1 Answers

1
votes

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