| |
| Posted by Benji Smith | PermalinkReply |
|
Benji Smith
| First of all, Walter, it would be nice if there was a separate newsgroup for implementation issues encountered when writing code in D. I hate to post this message--with its admittedly limited general interest--in a newgroup primarily devoted to language design issues, but there doesn't currently seem to be any choice.
Having said that, I'm having some with getting runtime Access Violation errors whenever I try to access an object whose definition appears inside a template. The error appears whenever I try to access the object's member data or functions. It looks like the object reference is dereferencing as a null pointer, which explains the Access Violation exception from windows. But I can't see what's wrong with the code.
The simplified example below shows the way I'm setting up my code. I've left out the actual implementations of my methods, since it doesn't seem to matter how I implement them. I don't get any compile-time errors, so the syntax appears to be ok.
I've stepped through the machine code in a debugger and, though I'm not an expert in assembly language, I'm pretty sure that the exception is thrown when the object is dereferenced to either call a function or access a data member.
Is this a bug or am I missing something fundamental in my template definition/instantiation syntax?
Thanks,
--Benji Smith
******************************
CODE FOLLOWS:
******************************
template TStack(T) {
class Stack: Object {
private T[] stackArray;
private int stackArrayPointer = 0;
public int depth;
public void setLength(int stackArraySize) {
..
}
public void push(T data) {
..
}
public T pop() {
..
}
}
}
class DocBuilder {
private instance TStack(char[]).Stack tagStack;
build() {
tagStack.setLength(50);
tagStack.push("EXAMPLE");
stackDepth = tagStack.depth;
char[] x = tagStack.pop();
}
}
|