0

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;
}
  • Please refer to the linked Q&A. If the problem persists, [edit] this question or ask a new one, providing relevant information about your project (what is your tasks.json, the full build log, etc). – n. 1.8e9-where's-my-share m. Dec 26 '21 at 16:08

0 Answers0