1

Recently I had to migrate one of my small turn-in projects from VS to CodeBlocks. In VS the project worked and run just fine.

Now that I have moved my .cpp and .h to CB it runs to an error and I can't see why, because I am referring to the Menu.h.

Main:

#include <iostream>
#include "Menu.h"
#include "Bulk.h"
#include "Parcel.h"
#include <fstream>

using namespace std;

int main()
{
    Menu m1 = Menu();
    m1.Start();
}

Menu.cpp:

#include "Menu.h"
#include "Material.h"
#include "Bulk.h"
#include "Parcel.h"
#include <iostream>
#include <string>
#include <deque>

using namespace std;

deque<Parcel> Parcels;
deque<Bulk> Bulks;

void Menu::Start()
{
    string selection = "F";
    for (int i = 0; i < 1;)
    {
        cout << "*****Warehouse Manager*****\n";
        cout << "1 - Add Material\n";
        cout << "2 - List Materials\n";
        cout << "3 - Add Stock\n";
        cout << "4 - Decrease Stock\n";
        cout << "E - Exit\n";

        cin >> selection;

        if (selection == "1")
        {
            AddMaterial();
        }
        if (selection == "3")
        {
            AddStock();
        }
        if (selection == "2")
        {
            PrintAll();
        }
        if (selection == "4")
        {
            RemoveStock();
        }
        if (selection == "E")
        {
            i++;
        }


    }
}
void Menu::RemoveStock()
{
    string code;
    double stock;
    cout << "Please enter ID Code:\n";
    cin >> code;
    cout << "Please enter value:\n";
    cin >> stock;


    for (int i = 0; i < Parcels.size(); i++)
    {
        if (Parcels[i].GetEAN() == code)
        {
            Parcels[i].DecreaseStock(stock);
        }
    }

    for (int i = 0; i < Bulks.size(); i++)
    {
        if (Bulks[i].GetIDCode() == code)
        {
            Bulks[i].DecreaseStock(stock);
        }
    }



}


void Menu::PrintAll()
{
    for(int i = 0; i < Parcels.size(); i++)
    {
        Parcels[i].Print();
    }

    for (int i = 0; i < Bulks.size(); i++)
    {
        Bulks[i].Print();
    }
}

void Menu::AddStock()
{
    string code;
    double stock;
    cout << "Please enter ID Code:\n";
    cin >> code;
    cout << "Please enter value:\n";
    cin >> stock;


    for (int i = 0; i < Parcels.size(); i++)
    {
        if (Parcels[i].GetEAN() == code)
        {
            Parcels[i].IncreaseStock(stock);
        }
    }

    for (int i = 0; i < Bulks.size(); i++)
    {
        if (Bulks[i].GetIDCode() == code)
        {
            Bulks[i].IncreaseStock(stock);
        }
    }



}


void Menu::AddMaterial()
{
    string selection = "F";
    cout << "Please choose:\n";
    cout << "1 - Parcel\n";
    cout << "2 - Bulk\n";

    cin >> selection;

    if(selection == "1")
    {
        string name;
        string company;
        string ean;
        double pieceprice;

        cout << "Please enter material name:\n";
        cin >> name;
        cout << "Please enter the company:\n";
        cin >> company;
        cout << "Please enter the EAN ID:\n";
        cin >> ean;
        cout << "Please enter the price:\n";
        cin >> pieceprice;

        Parcel p1 = Parcel(name, company, ean, pieceprice);
        Parcels.push_front(p1);
    }

    if (selection == "2")
    {
        string name;
        string company;
        string idcode;
        string unit;
        double unitprice;

        cout << "Please enter material name:\n";
        cin >> name;
        cout << "Please enter the company:\n";
        cin >> company;
        cout << "Please enter the ID:\n";
        cin >> idcode;
        cout << "Please enter the unit:\n";
        cin >> unit;
        cout << "Please enter price per 1 unit:\n";
        cin >> unitprice;

        Bulk b1 = Bulk(name,company,idcode,unit,unitprice);
        Bulks.push_front(b1);
    }

}

Menu.h:

#pragma once
#include "Material.h"
#include "Bulk.h"
#include "Parcel.h"
#include <iostream>
#include <string>
#include <deque>

using namespace std;

class Menu
{
public:
    void Start();
    void AddMaterial();
    void AddStock();
    void PrintAll();
    void RemoveStock();
private:

};

The error is the following:

Error message

Do you guys have any idea what is going on? How come that it runs perfectly in VS but not in CB?

Thank you!

  • Are you linkind the results of compiling `Main` and `Menu.cpp`? – fabian Jan 16 '22 at 12:18
  • See: [What is an undefined reference/unresolved external symbol, and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix). – WhozCraig Jan 16 '22 at 12:23
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – BoP Jan 16 '22 at 13:41

0 Answers0