Click here to Skip to main content
15,995,361 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm a beginner in C++ and learning OOP. I wrote the main file, a header and a class implementation file

Main file (main.cpp):-

C++
#include 
#include "cylinder.h"

int main(){
    
    Cylinder cylinder1(10,10);
    std::cout << cylinder1.volume() << std::endl;

    return 0;
}


Header file (cylinder.h):-

C++
#ifndef cylinder_h
#define cylinder_h

class Cylinder{
	private:
		double radius;
		double height;

	public:
		Cylinder() = default;
		Cylinder(double r, double h);
		double volume();
};

#endif


Class implementation file (cylinder.cpp):-

C++
#include "cylinder.h"

Cylinder::Cylinder(double r, double h){
	radius = r;
	height = h;
}
double Cylinder::volume(){
	return 3.14*radius*radius*height;
}


When I run the class implementation file I get error

Quote:
undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status


What I have tried:

I have tried it on VS Code and if the entire class is in the header file the program works just fine. The problem arises when the I split the class into header file and the cpp implementation file.
Posted
Updated 20-Sep-22 21:13pm
v2

1 solution

Probably your IDE (o whatever) is trying to build a Windows GUI application, while you need a Console application. Check your build settings (or post here more details).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900