Errors with creating header files

In part 3 of the C++ course in the creating objects video, I’m having trouble with creating the class in visual studio code.

#include “rectangle.hpp”
using namespace std;

int main() {
rectangle rectangle;
rectangle.width = 10;
rectangle.height = 20;
cout << rectangle.getArea();
return 0;

#include “rectangle.hpp”
using namespace std;

void rectangle::draw() {
cout << “Drawing a rectangle” << endl;
cout << "Dimensions: " << width << ", " << height << endl;

int rectangle::getArea() {
return width * height;


class rectangle {
int width;
int height;
void draw();
int getArea();


This is my code and this is the error that comes up when I run it.

C:/msys64/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/12.2.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: C:\Users-------\AppData\Local\Temp\cck5lW42.o:main.cpp:(.text+0x23): undefined reference to rectangle::draw()' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\--------\AppData\Local\Temp\cck5lW42.o:main.cpp:(.text+0x2f): undefined reference to rectangle::getArea()’
collect2.exe: error: ld returned 1 exit status

What I think is happening is that I am unable to compile all of the files together at once. Does anyone have any fixes?

Change your class name from rectangle from Rectangle. When creating object it cannot find the identifier for your type rectangle. It is like declaring int int;


Change the second line to #include <iostream> if it is not an error while copying.

I have same problem. Did you solved it? if you did, please can you help me?

I have posted the solution. If it is something else then ask a new question or post the new error after trying the solution (if any).