I am new to c++ ,and i was trying to implement a basic rectangle class that takes width and height as a parameter and prints out the area on x code, now when i try to run it , build fails and i get the following error message:
Undefined symbols for architecture x86_64:
"Rectangle::Rectangle()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I looked at similar answers and i can't make it work for me. Any idea? I appreciate your help.
// here is Rectangle.hpp
#ifndef Rectangle_hpp
#define Rectangle_hpp
#include <stdio.h>
class Rectangle {
public :
int width,height;
Rectangle();
Rectangle (int a,int b);
int area();
};
#endif /* Rectangle_hpp */
// and here is the Rectangle.cpp
#include "Rectangle.hpp"
#include <iostream>
using namespace std;
Rectangle::Rectangle(int a, int b)
{
width = a;
height = b;
}
int Rectangle::area()
{
return (width*height);
}
// and here is main.cpp
#include "Rectangle.hpp"
#include <iostream>
using namespace std;
int main() {
Rectangle rect(3,4);
Rectangle rectb;
cout << "rect area: " << rect.area() << endl;
cout << "rectb area: " << rectb.area() << endl;
return 0;
}