Constraint for one hot encoded vectors in SV

Hi Dave,

I ran the program and i am getting compile Error. Can you help?

module top;
class A;
randc bit [24:0] vector;
constraint one_hot { $countones(vector) == 1; }
endclass

A h;

initial begin
h = new;
repeat (25) begin
assert (h.randomize());
$displayb(h.vector);
end
end
endmodule

rror-[IVCB-NORANDC] Illegal use of randc variable
design.sv, 5
top, “this.vector”
The expression contains the variable vector of type randc and cannot be used
in solve-before, distribution, unique and function calls.
Change the type of the randc variable or remove it from the expression.