Accessing variables from the instantiated class

Hi
Is there a way through which I can access the variables of a class from instantiated class.
For example:

I want to access shapes.a , shapes.b, shapes.c from triangle.get_abc function.



class triangle;
int x;
int y;
int z;

function get_abc;
.......
endfunction
endclass

class shapes extends uvm_component;
int a;
int b;
int c;

triangle tri;
  function new(string name, uvm_component parent);
    super.new(name, parent);

	tri = new();

  endfunction

//I donot want to do this:
// tri.x =a;
// tri.y =b;
endclass



In reply to kartavya:
Isn’t the class triangle an UVM class?
If not and you can update the class triangle, then you can pass a,b,c to the get_abc() function as

//In triangle class
function get_abc(int a,b,c);
  {x,y,z} = {a,b,c};
endfunction

// In shapes class
tria.get_abc(a,b,c);

Please note that you can’t use “tri” as object name because it’s data type.

In reply to kartavya:

What you are asking for does not seem feasible without passing a shapes handle to triangle. You constructed an instance of a triangle object inside of a shapes object. The triangle object has no information about how it got constructed. In fact the triangle objects handle could be passed to another unrelated class object and the shapes object Ould disappear.

You would need to create a circular reference (which is generally not a good idea) with

typedef class shapes; // forward typedef for circular reference
class triangle;
  shapes sha;
  int x;
  int y;
  int z;
 
  function get_abc;
    // can reference  sha.a sha.b sha.c. here
  endfunction
endclass
class shapes;
  int a;
  int b;
  int c;
  triangle tri;
  function new;
    tri = new(this);
  endfunction
endclass