0

I have a programme written on C++ its Warehouse. I need to visualise it with the WinAPI. I created central DialogBox with the list of Menu, depending on selected buttons different methods should be called. I included all needed header files into stdafx.h

#include "targetver.h"

#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>

// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include"ConstructMaterials.h"
#include"Visitor.h"

Ny project name is Sklad, so in Sklad.cpp I created global objects, that represents warehouse and class Visitor(I use this pattern) to define to which department these goods should belong to.

 Warehouse w;
 Visitor v(w);

For ex I want to show all current goods that are on the stock. For this purpose I call class Warehouse method:

INT_PTR CALLBACK MainScreen(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    UNREFERENCED_PARAMETER(lParam);
    switch (message)
    {
    case WM_INITDIALOG:
            w.loadExistingData();
        return (INT_PTR)TRUE;

    case WM_COMMAND:
        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
        {
            EndDialog(hDlg, LOWORD(wParam));
            return (INT_PTR)TRUE;
        }
        if(LOWORD(wParam) == IDC_BUTTON3)
        {
            DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG2), hDlg, Show);
        }
        break;
    }
    return (INT_PTR)FALSE;
}

the called methos looks like that:

void Warehouse::loadExistingData()
{
    Visitor v(*this);
    Goods*cement=new ConstructMaterials();
    cement->SetGoods("cement", 20, "Ukraine", "tn", 2016, 1, 25);
    cement->AddMe(v);
    Goods*pen=new OfficeStuff();
    pen->SetGoods("pen", 50, "Poland", "pcs", 2020, 1, 1);
    pen->AddMe(v);
    Goods*ink=new OfficeStuff();
    pen->SetGoods("ink", 50, "Finland", "pcs", 2016, 2, 17);
    pen->AddMe(v);
    Goods*Laundry=new HomeAppliances();
    Laundry->SetGoods("laundry", 2, "China", "pcs", 2017, 11, 2);
    Laundry->AddMe(v);
    Goods*microwave=new HomeAppliances();
    microwave->SetGoods("microwave", 5, "France", "pcs", 2014, 5, 8);
    microwave->AddMe(v);
    Goods*metal=new ConstructMaterials();
    metal->SetGoods("metalPipes", 50, "Russia", "tn", 2030, 1, 1);
    metal->AddMe(v);
}

But during compilation I got an error: 1>Sklad.obj : error LNK2019: unresolved external symbol "public: void thiscall Warehouse::loadExistingData(void)" (?loadExistingData@Warehouse@@QAEXXZ) referenced in function "int __stdcall MainScreen(struct HWND *,unsigned int,unsigned int,long)" (?MainScreen@@YGHPAUHWND__@@IIJ@Z) 1>E:\Sklad\Debug\Sklad.exe : fatal error LNK1120: 1 unresolved externals header of Warehouse looks:

#ifndef W
#define W
//#include"Goods.h"
#include<vector>
#include<fstream>
#include"ConstructMaterials.h"
#include"HomeAppliances.h"
#include"OfficeGoods.h"
//#include"Visitor.h"
//class Visitor;

class Warehouse
{
public:
    vector<ConstructMaterials>constructMaterials;
    vector<OfficeStuff>officeStuff;
    vector<HomeAppliances>homeAppliances;
    //Warehouse();
    void Menu();
    void Show();
    void loadExistingData();
    void Insert();
    void DispatchGoods();
    void GoodsThatValidOneWeek();
    void ReviewExpiredGoods();
    void SaveToFile();
    void LoadDataFromFile();
    //~Warehouse();
};


#endif

I saved this project on the google disc, so if it could help to clear the issue I will be thenkfull.

I am totaly lost with how to manage it.

Thanks in advance.

Melany
  • 466
  • 7
  • 20
  • This is C++ not C. Please remove C tag. – Frankie_C Mar 05 '16 at 23:30
  • 1
    Are there other compilation errors. It's unclear from the information provided but is the warehouse deceleration part of this project. The link error means that when the linker went to link the binary from obj and lib files there was no code for that method call. It's common when using external libraries and you don't provide the linker with the lib files – MDK Mar 05 '16 at 23:31
  • 1
    Where is `Warehouse` defined? In what header? Are you including that header in your `Sklad.cpp` or `stdafx.h`? The information provided its not enough to determine where does the link error come from. – Nacho Mar 05 '16 at 23:37
  • 1
    Probably `void Warehouse::loadExistingData()` is defined in a different file, and you have not included that file in your project. You should leave `stdafx.h` alone, use your own header files instead. – Barmak Shemirani Mar 06 '16 at 00:28
  • &MDK I dont use any external libraries – Melany Mar 06 '16 at 07:30
  • @Nacho Warehouse has its own header file and cpp. I added Header of warehouse into my post – Melany Mar 06 '16 at 07:58
  • @Barmak Shemirani You mean include all header files in my Sklad.cpp? What is strange that when I declare the object of Warehouse everything is visible, but when try to use some methods of this class it reflect these errors. – Melany Mar 06 '16 at 08:05
  • 1
    Just drag and drop all related *.cpp files in your project. – Barmak Shemirani Mar 06 '16 at 08:30
  • @ Barmak Shemirani Thanks. In my previous project I had a lot of headache with cross-connected headers - and in console project I managed to orginise it in correct way. So I was afraid to have such a mess here. Ones again thanks a lot. I will try to do like this))) – Melany Mar 06 '16 at 09:30
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – IInspectable Mar 07 '16 at 17:17

0 Answers0