I have a starter project and I need to write a custom allocator and diagnostic tools for it. I made a class Class
in which I have 2 methods for the custom allocator void alloc()
void dealloc()
and for the diagnostic tools void evaluate()
.
Now, I declared an object test
of type Class
in CustomAllocator.h
and use the 2 methods to allocate and deallocate memory with no problems. But when I try to call the evaluate()
method in CustomAllocatorTest.cpp
I got the linker error class Class test(?test@@3VClass@@A) already defined in CustomAllocatorTest.obj
and LNK1169 one or more multiply defined symbols found
.
Class.h
#pragma once
class Class
{
public:
void alloc() { std::cout << "alloc"; }
void dealloc() { std::cout << "dealloc"; }
void evaluate() { std::cout << "evaluate"; }
};
CustomAllocator.h
#ifndef _CUSTOM_ALLOCATOR_H_
#define _CUSTOM_ALLOCATOR_H_
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#include <stdlib.h>
#include "Class.h"
Class test;
#endif // _CUSTOM_ALLOCATOR_H_
CustomAllocator.cpp (#include "stdafx.h" includes "CustomAllocator.h")
#include "stdafx.h"
using namespace std;
int main()
{
test.evaluate();
return 0;
}