Currently learning about header files in VS code on Mac OS. I was having trouble with the header file, so I created a simple fruit class. The error still persist.
Error
Undefined symbols for architecture x86_64: "Fruit::Fruit()", referenced from: _main in main-45e875.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Header File
//Fruit.hpp
#pragma once
#ifndef FRUIT_H
#define FRUIT_H
#include <iostream>
class Fruit
{
private:
std::string name;
double weight;
public:
Fruit ();
Fruit (std::string name);
Fruit (double weight);
Fruit (std::string name, double weight);
};
#endif
Cpp File
// Fruit.cpp
#include "Fruit.hpp"
Fruit::Fruit()
{
this->name = "Banaple";
this->weight = 420.69;
}
Fruit::Fruit(std::string name)
{
this->name = name;
this->weight = 420.69;
}
Fruit::Fruit(double weight)
{
this->name = "Pineapple";
this->weight = weight;
}
Fruit::Fruit(std::string name, double weight)
{
this->name = name;
this->weight = weight;
}
Main File
// main.cpp
#include <iostream>
#include "Fruit.hpp"
int main(){
Fruit apple;
return 0;
}