I am new to ubuntu, now I need to develop my assignment in C++. I am using codeblocks IDE to write c++ programs. Whenever I compile something in it, it gives these errors:
The program compiles fine with (yourcode.cc contains your sourcecode):
$ CXXFLAGS="-Wall -Werror -Wpedantic" make yourcode
stack.cc: In member function ‘int List::get()’:
stack.cc:76:1: error: control reaches end of non-void function [-Wreturn-type]
}
and invoking ./yourcode
outputs:
List size = 5
Element 1 2
Element 2 6
Element 3 8
Element 4 7
Element 5 1
Obviously your IDE is going to add some flags to the linker. Please show us your compile flags/setting. See the compile log or run the make command executing more verbose.
May have a look at. Code::blocks verbose build
It seems that your IDE is not just compiling one single file, but another one which also contains a definition of the main function. Please check out how many files are being compiled.
In addition, your compiled is treating all the warnings as errors (-Werror) or disable this flag.
The Problem was just, my IDE was compiling multiple files at once,
and also in the function int List::get()
,
I got to add else return -1
at the end of this function after if statement,
I mean before editing my code the int List::get()
function was like this:
int List::get() {
if (currentNode != NULL)
return currentNode->get();
}
I replaces this one with:
int List::get() {
if (currentNode != NULL)
return currentNode->get();
else return -1;
}
and it worked fine.