SystemVerilog class arguments

Hi,
I am relatively new to systemverilog and was wondering if i could get some guidance on classes. I have been trying to create a class which contains a function which when called will take a subclass name and instantiate it.I which two have two objects of the same class each with unique subclasses.

In reply to rbrtbrennan1:
You can’t pass the name of a type as an argument to a function. What you can do is either pass a string or some other encoded value as an argument and have the function branch to s statement that constructs the requires class, or you can use a proxy class object. A proxy class sole purpose is to stand in for the actual class you want to create with a virtual method.

class base;
endclass
class subclass1 extends base;
endclass
class subclass2 extends base;
endclass

virtual class base_proxy;
pure virtual function base create;
endclass

// this assumes T is a subclass of base
class wrapper #(type T) extends base_proxy;
  virtual function T create;
    create = new;
  endfunction
endclass

class A;

base b_h;

function myFunction(proxy proxy_h);
    b_h = proxy_h.create();
endfunction

endclass

Now in you can pass different wrapper class objects to your myFunction

base h1, h2;

h1 = wrapper#(subclass1)::new;
h2 = wrapper#(subclass2)::new;

myFunction(h1);

Proxy classes are used with the factory pattern. See my SystemVerilog OOP course, especially the third session of proxy classes and the factory.

In reply to dave_59:

You actually have no idea how much you have helped me, Thank you so much. I need to look over and read up on the course you have linked me but I have been tearing my hair out finding where to figure this out! Thank you!