I personally hate asking for debugging help, but as it happens, I'm on my third day in a row of googling solutions with an answer to how to fix this.
I have a C++ error which complains that my fileBufferTransformable::fileBufferTransformable() function has multiple definitions;
This is the code:
fileBuffer/fileBufferTransformable.hpp :
- Code: Select all
#ifndef fileBufferTransformable_h
#define fileBufferTransformable_h
class fileBufferTransformable
{
public:
fileBufferTransformable();
};
fileBufferTransformable::fileBufferTransformable() // THIS IS THE LINE THE COMPILER IS COMPLAINING ABOUT
{
}
#endif
fileBuffer/fileBufferRef.cpp :
- Code: Select all
#ifndef fileBufferRef_h
#define fileBufferRef_h
#include "fileBufferTransformable.hpp"
#endif
main.cpp :
- Code: Select all
#include "fileBuffer/fileBufferRef.cpp"
int main()
{
return 0;
}
Error console:
- obj\Debug\fileBuffer\fileBufferRef.o||In function `fileBufferTransformable':|
...\fileBuffer\fileBufferTransformable.hpp|30|multiple definition of `fileBufferTransformable::fileBufferTransformable()'|
obj\Debug\main.o:...\fileBuffer\fileBufferTransformable.hpp|30|first defined here|
obj\Debug\fileBuffer\fileBufferRef.o||In function `fileBufferTransformable':|
...\fileBuffer\fileBufferTransformable.hpp|30|multiple definition of `fileBufferTransformable::fileBufferTransformable()'|
obj\Debug\main.o:...\fileBuffer\fileBufferTransformable.hpp|30|first defined here|
||=== Build finished: 4 errors, 0 warnings ===|
The goal of this is to have a package of usable files which, just by including fileBuffer/fileBufferRef.cpp, would all be included to make my life easier. I've managed to do this before with a package of classes, but this doesnt seem to work.
The research did get me to understand that somehow, the compiler is compiling the function twice, but I have no idea why. And besides, the file is never included twice, how could that even happen? A partial solution I found was to use inline on the function, which I have tested and found to work, but I'm wondering if there is a better solution. According to people, the inline solution doesn't solve the problem with the compiler reading the function twice, the compiler simply ignores it if it has inline set.
Any plaintext solutions would be greatly appreciated!
-WallShadow <3



