Class Member Print Out

 

Let's assume I have one class defined as follows:


class Test

{

public:

string CheckValue

Test ()

{};

};

Ontick

{

Test MyObject;

}

How can I have following Print Out

(I want to create a function, that returns the member of the class/object)

List of MyObject Members:

string Checkvalue

I don't have any use for this yet, just doing for studying purpose


Thank You in advance

 

There is no simple way to do that, you need to code it yourself.

Please use the appropriate formatting when you post code.


 

MQL5 does not provide reflection/introspection to enumerate class members at runtime, so you can’t generically print “all members of MyObject” like in languages with RTTI/reflection.

The usual approach is to implement it manually (or via a macro) by writing a  ToString()  /  Dump()  method that returns the fields you care about.

Example:

class Test
{
public:
string CheckValue;
Test() { CheckValue=""; }
string Dump() const
{
return StringFormat("Test{ CheckValue='%s' }", CheckValue);
}
};
void OnTick()
{
Test my;
my.CheckValue = "abc";
Print(my.Dump());
}

If you want something closer to “list of members”, you still have to maintain the list yourself (e.g. print field names + values), or use an external code-generation step (not available inside MT5 runtime).