Please tell me how to overcome the problem?
error LNK2005: already defined in .obj
I can’t already, that I haven’t tried both #pragma once
and #infndef
and together, I just can’t beat this problem.
I have a file in which the compare and delete functions for the classes are located. This is done to simply declare a function pointer in another class and pass the necessary function there. But in this file you need to use the declared classes. That is, cross-inclusion.
Here is the file
#ifndef HLPFUNC_H #define HLPFUNC_H #include "departament.h" #include "brand.h" #include "model.h" #include "quality.h" #include "parts.h" #include "reptype.h" #include "pointerArray.h" void delDprt(void *delEl) { delete (departament*)(delEl); } void delBrnd(void *delEl) { delete (brand*)(delEl); } void delMdl(void *delEl) { delete (model*)(delEl); } void delRprTp(void *delEl) { delete (reptype*)(delEl); } void delPrts(void *delEl) { delete (parts*)(delEl); } void delQlty(void *delEl) { delete (quality*)(delEl); } int cmpDprt(void *p, string key) { if (((departament*)p)->name == key) { return 0; } else { if (((departament*)p)->name > key) { return 1; } else {return -1;} } } int cmpBrand(void *p, string key) { if (((brand*)p)->name == key) { return 0; } else { if (((brand*)p)->name > key) { return 1; } else {return -1;} } } int cmpModel(void *p, string key) { if (((model*)p)->name == key) { return 0; } else { if (((model*)p)->name > key) { return 1; } else {return -1;} } } int cmpRprType(void *p, string key) { if (((reptype*)p)->name == key) { return 0; } else { if (((reptype*)p)->name > key) { return 1; } else {return -1;} } } int cmpParts(void *p, string key) { if (((parts*)p)->name == key) { return 0; } else { if (((parts*)p)->name > key) { return 1; } else {return -1;} } } int cmpQlty(void *p, string key) { if (((quality*)p)->qlt == key) { return 0; } else { if (((quality*)p)->qlt > key) { return 1; } else {return -1;} } } #endif
Accordingly, in each of the classes you need to include this file. I tried to divide this file into separate header and header, included this file in the lowest class, and then included in the hierarchy upward the lower class. Nothing helps, that is, the files themselves are compiled into object files normally, but the linking does not go away. Help me please. I do not know what to think of even ...