Hello,
I just installed Code::Blocks and I use the GNU GCC Compiler. Then I tried to add some working code(tested in visual studio successfully), and the code was:
// overloading operators example
#include <iostream>
#include <string>
using namespace std;
int nopel;
class ArrayWrapper
{
public:
// default constructor produces a moderately sized array
ArrayWrapper()
: _p_vals(new int[64])
{
std::cout << "in arraywrapper constructor no arg";
}
ArrayWrapper(int n)
: _p_vals(new int[n])
{
std::cout << "in arraywrapper constructor args";
}
// move constructor
ArrayWrapper(ArrayWrapper&& other)
: _p_vals(other._p_vals)
{
std::cout << "in arraywrapper move constructor";
other._p_vals = NULL;
}
// copy constructor
ArrayWrapper(const ArrayWrapper& other)
: _p_vals(new int[5])
{
std::cout << "in arraywrapper copy constructor";
for (int i = 0; i < 6; ++i)
{
_p_vals[i] = other._p_vals[i];
}
}
~ArrayWrapper()
{
delete[] _p_vals;
}
private:
int *_p_vals;
};
void tryer(int&& i) { i = 12; }
int main() {
system("pause");
return 0;
}
It all works just as expected in visual studio as mentioned before, but when I try to compile it in Code::Blocks, I get all these weird errors:
||=== Build file: "no target" in "no project" (compiler: unknown) ===|
C:\Users\ss\Documents\c++ files\tryy.cpp|29|error: expected ',' or '...' before '&&' token|
C:\Users\ss\Documents\c++ files\tryy.cpp|29|error: invalid constructor; you probably meant 'ArrayWrapper (const ArrayWrapper&)'|
C:\Users\ss\Documents\c++ files\tryy.cpp|57|error: expected ',' or '...' before '&&' token|
C:\Users\ss\Documents\c++ files\tryy.cpp||In function 'void tryer(int)':|
C:\Users\ss\Documents\c++ files\tryy.cpp|57|error: 'i' was not declared in this scope|
C:\Users\ss\Documents\c++ files\tryy.cpp||In function 'int main()':|
C:\Users\ss\Documents\c++ files\tryy.cpp|61|error: 'system' was not declared in this scope|
||=== Build failed: 5 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Can anybody please tell me how I can fix this? I mean it is pretty frustrating when it all should work and works in visual studio.
Thanks!!
Codeblocks is a IDE, not a compiler. You get compiler errors so this is the wrong forum to ask this kind of questions. We support only codeblocks not the underlying compiler...
One thing i noted:
C:\Users\ss\Documents\c++ files\tryy.cpp|29|error: expected ',' or '...' before '&&' token|
this comes probably from:
ArrayWrapper(ArrayWrapper&& other)
so you are using a new c++ feature. You need at least GCC 4.3 to use RValue reference and you will enable c++11 by adding the "-std=c++11" compiler flag to the build options