Board index » cppbuilder » Re: Additionally

Re: Additionally


2003-07-13 03:32:31 AM
cppbuilder57
"Bob" < XXXX@XXXXX.COM >wrote:
Quote

"ta0kira" < XXXX@XXXXX.COM >wrote:
>How do I create a pointer to any class?
In addition to a Variant, you could use any type pointer since
all you're doing is storing the address and then you just cast
it as needed.
I suppose that there might be an exception but I can't think
of one. Just be sure that if/when you delete it that it is of
the same type when it was allocated.
 
 

Re:Re: Additionally

Thanks. Since the time I posted, I came up with a template class that stores any pointer as a void*, then re-casts it to a pointer of the object type as needed. Works pretty well, however functions that take the template class as an argument require that the class type is declared, therefore I need to declare those funtions as templates. Something I thought about is: if a method needs a pointer to an object, it will need to know the type beforehand in order to deal with it, unless it is just storing it or transfering it to another object. In those cases the class I made will work. Thanks for your help.
ta0kira
 

Re:Re: Additionally

"ta0kira" < XXXX@XXXXX.COM >wrote:
Quote
[...]
You really need to start wrapping your lines when you post.
What that means is that although you may see words wrap, you
still need to add a hard return to the end of each line.
 

{smallsort}

Re:Re: Additionally

The pointer will be used more for reference; in another class I
have funtions that take the ID of an object using the funtion.
It is easier to have the template as a class than put a template
in all classes that take a void* reference.
Anyway, I am encountering a problem with my class. I have it working perfectly as of now, however if I add any additional
declarations I will get return errors with the functions.
Declarations before:
private:
bool PointerIsSet;
void *Pointer;
char *PointerType;
time_t IDTime;
int PID;
Declarations after:
private:
bool PointerIsSet;
void *Pointer, *POwner;
char *PointerType;
time_t IDTime;
int PID;
With the addition of the *POwner declaration the class either
does not function (will compile either way), or the methods
don't consistently return values. What I have tried:
1. change void *POwner declaration to int POwner
2. change name of POwner to a random word
3. declare it on its own line
4. Set its value in the constructors
I still got the same result, but when I deleted the declaration
it worked fine. After declaring/removing the additional
void*/int several times the class did not function at all, even
though it was the same code as when it worked. I ended up
having to revert to a saved copy, which worked, but still got
the errors with the additional declarations.
Does this sound like my error or a system error? Thanks
ta0kira