I have a copy constructor, declared
explicit, that takes a reference to the same type, like a normal copy constructor. However, it's not behaving. I've placed debugging information (with the pre-processor) within the body of the copy constructor, but even that isn't printing.
Due to this behaviour, I have concerns regarding how the memory is copied, not transferred, from one class to another.
Here's my constructor:
1 2 3 4 5 6 7 8 9 10 11
|
template <typename T>
MemoryRegion<T>::MemoryRegion(const MemoryRegion<T> &Region)
: Def_Size_(Region.Def_Size_),
Bs_Ptr_(Region.Copy()),
Lt_Ptr_((Bs_Ptr_) ? &Bs_Ptr_[(Def_Size_ - 1U)] : 0)
{
#if defined MEMORY_REGION_DEBUG_DEF
std::cout << "DEBUG -> Region.Capacity: " << Region.Capacity() << '\n';
std::cout << "DEBUG -> Capacity: " << this->Capacity() << '\n';
#endif
}
|
Here's a quick overview of what happens here: First,
Def_Size_ attains the region size of
Region. Then,
Bs_Ptr_ is assigned to the pointer returned by
Region.Copy() (
MemoryRegion<T>::Copy() copies the region of the associated class and returns a pointer to it). Finally,
Lt_Ptr_ is set to point to the last item within the region.
Before proceeding, note the destructor definition:
1 2 3 4 5 6 7 8 9 10 11 12
|
template <typename T>
MemoryRegion<T>::~MemoryRegion()
{
#if defined MEMORY_REGION_DEBUG_DEF
if(!this->Bs_Ptr_)
std::cout << "DEBUG -> Bs_Ptr_ doesn't require deletion" << '\n';
else std::cout << "DEBUG -> Bs_Ptr_ requires deletion" << '\n';
#endif
delete [] this->Bs_Ptr_;
}
|
Now, the output should be (or something similar to):
DEBUG -> Region.Capacity: 2048
DEBUG -> Capacity: 1024
DEBUG -> Bs_Ptr_ requires deletion
|
Here's the twist: There's no output, no thrown exceptions, no crashes - nothing, and I don't know why.
MEMORY_REGION_DEBUG_DEF is definitely defined, by the way.
Thoughts?
P.S: Mind the makeshift debugging, and naming conventions.
Wazzak