I think that this is a double deletion error. |
ofc, I designed it that way then made an oversimplified example where each bit occured in sequence and this made it not work :¬o Thanks, couldn't see the wood for the trees. Hopefully that will solve it. It was working entirly as it was suposed to.
which means the ptr class will only work with pointers to 'number's |
I hope to make it generic later.
The idea is that the pointer deletes the target object when nothing is pointing to it, like in Java. Being a pointer it needs to be able to point to anything and members called on it need to be able to be passed to the object it is pointing to. I will do this though the follow member function.
ty for that. I remeber that producing a compile error. I will try again.
What Disch said. void* has been deprecated in C++. We now use reinterpret_casts, and dynamic_casts. |
This is the first I have heard that void* has been offically deprecated. I want to avoid constructing my pointer with a template like this.
ptr<number> p1;
I don't know if I can achieve the same thing with reinterpret_casts or dynamic_casts instead of void*.
I wish to be able to point the pointer at an int, do some int things then a std::string and call std::string members without loss of generic functionality or complicated syntax for the user.
void* allows for a lot of stuff that doesn't work with just templates. I can get an example later of a template function that is given two parameters, an object and a bool, if the bool is true it couts the object, if false then it couts the output of the length member of the object.
It is a trivial example but seemingly impossible not to get a compilation error when calling the function with <int>(int, true) and <std::string>(std::string, false) in the same program. The compiler complains that the int doesn't have a length member, even though the code never actually calls length on the int, only the string.
I can aprecate that this is the compiler trying to force type safety, but not everyone likes type safety, in some langueges you never specify things like return types and any member can be called on anything without hastle (unless you make a mistake).
Other langueges go the other way and are much more type safe than C++, which type safety proponents I know prefer to C++. C++ is verry complicated however and many people like this, especally now with two new types of casting, which appear to have complicated rules about how they work and undoubtedly complicated circumstances in which they will and won't work.
Quick example of C++ having complicated exceptions to behaviour.
works:
1 2 3 4 5 6 7 8 9 10 11
|
class c2
class c1
{
public:
c2* a;
};
class c2
{
};
|
fails (spot the suble difference):
1 2 3 4 5 6 7 8 9 10 11
|
class c2;
class c1
{
public:
c2 a;
};
class c2
{
};
|
Sorry, way off topic, I will try the fixes probbably tomorow.