Edit with respect to solution suggestion: The solution for the author of the question was that he put the main function into a namespace. Then he added parameters to the main function, then he used extern "C" in order to get his main to be recognized as entry point. Answers, which looked detailed suggested that the code author did not define a main/win main function (which was debated). I also don't use Visual C++, but a mingw version which works on my AMD computer (its a win 64 variant on a windows 10 home edition).
I have a problem, which seems frequently to find its way to StackOverflow and I could not locate any answer which helped me resolve my problem.
I used codeblocks and made a project as a console application. This is the code I tried to compile and I keep on getting the "undefined WinMain" error.
I used the win64 MinGW compiler, which came with codeblocks
Compiler Flags were: (-std=C++11
, -std=C++14
, and -std=C++17
. I used all of previous one at a time, before), -Wall, and -pedantic
This is the code and naturally, I was not able to resolve my problem. The attached images are "Build log" and "Build Messages" from the respective codeblock tabs of the "Logs & other window".
Please help.
#include <iostream>
using namespace std;
class Rectangle {
protected:
int width, height;
public:
Rectangle(int width = 0, int height = 0): width(width), height(height) {};
int get_width() const {return width;}
int get_height() const {return height;}
virtual void set_width(int width) {this->width = width;}
virtual void set_height(int height) {this->height = height;}
int area() const {return width * height;}
};
class Square : public Rectangle {
public:
Square(int size = 0) : Rectangle(size, size) {
set_width(size);
this->width = this->height = size;
}
void process(Rectangle &r){
r.set_height(10);
cout << "expected area was 30, got " << r.area() << std::endl;
}
int main() {
Rectangle r(3,4);
process(r);
std::cout << "Template" << std::endl;
return 0;
}
};