www.digitalmars.com         C & C++   DMDScript  

D - Cast causes access violation

reply Johnny <Johnny_member pathlink.com> writes:
I've got a class called Regex wich is an subclass of the interface Automate. In
some function I have a parameter which takes an automate.

public void fromAutomate(in Automate from)
{
Regex ex = (Regex)from;
}

I am sure this is a Regex because running the interface methods work as
expected. However, casting the Automate to the regex causes an access violation.

Please help,
Johnny
Mar 18 2004
parent reply Ilya Minkov <minkov cs.tum.edu> writes:
I think you should reduce this to a minimum self-contained example which 
compiles and fails in this manner (up to 20 lines of code) and try to 
post it with a [bug] in subject line. Walter needs such to find bugs and 
maintain a set of tests.

Else i don't see what would be causing it.

-eye

Johnny schrieb:
 I've got a class called Regex wich is an subclass of the interface Automate. In
 some function I have a parameter which takes an automate.
 
 public void fromAutomate(in Automate from)
 {
 Regex ex = (Regex)from;
 }
 
 I am sure this is a Regex because running the interface methods work as
 expected. However, casting the Automate to the regex causes an access
violation.
 
 Please help,
 Johnny
 
 
Mar 18 2004
parent johnnyvdlaar hotmail.com writes:
public interface Automate {}

public class NDFA : public Automate {
public void fromAutomate(in Automate from) {
printf("%d\n", (Regex)from);
}
}

public class Regex: public Automate {}

int main() {
Regex regex = new Regex();
NDFA ndfa = new NDFA();
ndfa.fromAutomate(regex);
return 0;
}

and all he prints is a 0

In article <c3c42t$1fg$1 digitaldaemon.com>, Ilya Minkov says...
I think you should reduce this to a minimum self-contained example which 
compiles and fails in this manner (up to 20 lines of code) and try to 
post it with a [bug] in subject line. Walter needs such to find bugs and 
maintain a set of tests.

Else i don't see what would be causing it.

-eye

Johnny schrieb:
 I've got a class called Regex wich is an subclass of the interface Automate. In
 some function I have a parameter which takes an automate.
 
 public void fromAutomate(in Automate from)
 {
 Regex ex = (Regex)from;
 }
 
 I am sure this is a Regex because running the interface methods work as
 expected. However, casting the Automate to the regex causes an access
violation.
 
 Please help,
 Johnny
 
 
Mar 18 2004