After [I] instantiate a struct object inside class...
class B
{
private:
Test test;
This is not instantiating anything. This declares that every (at this point, theoretical object of type B
will have a member variable named test
, of type Test
.
(Besides, get into the habit of making any member variable private
, not public
, as early on in your learning process as possible. A class
is not just a struct
with functions, it is an elementary OOP building block that should not expose its data members to public
-- doing so is usually a design error.)
A a(test); //error
This is not "passing [test
] as parameter to a constructor", as you stated!
This is declaring a member function to class B
named a
, which returns an object of type A
, and takes an unnamed parameter of type test
.... which, as there is no such type, just a member variable of that name, this an error.
As the overall purpose of your code example is rather unclear, it is difficult to say what would be "correct" for you.