class AAA;
rand int a;
rand bit b;
constraint aaa;
class BBB extends AAA ;
constraint aaa {a>4 && a<67 ; b>10 && b<90 ;}
endclass
endclass
module mode;
AAA p;
AAA::BBB q;
initial begin
p=new;
q=new;
repeat(10)
begin
assert(p.randomize());
$display("%0d , %0d",q.a,q.b);
end
end
endmodule
Asked
Active
Viewed 259 times
-1

Matthew Taylor
- 13,365
- 3
- 17
- 44
-
Class `BBB` is a _derived_ class **and** an _embedded_ class. Which of these do you mean by "child" class? – Matthew Taylor Sep 19 '19 at 08:36
-
Your constraint on `b` will always fail. – Matthew Taylor Sep 19 '19 at 08:37
-
Did you mean `q.randomize()`? – Matthew Taylor Sep 19 '19 at 08:37
1 Answers
0
You are mixing up inheritance (IS-A) with containers (HAS-A) and nested declarations. With inheritance, you just construct the extended class. If you construct the base class, that object has no knowledge of any extensions to it, including classes with nested class declarations.
There's no reason to use nested classes unless you need to hide the name of the nested class type from the general name space. Otherwise, a nested class behaves identically as if you had declared it without nesting it.

dave_59
- 39,096
- 3
- 24
- 63