How to use anonymous struct in C++

1 Answer

0 votes
#include <iostream>

using std::cout;
using std::endl;

struct Test
{
	struct
	{
		char ch;
		int n;
	};
};


int main()
{
	struct Test t;

	t.ch = 'z';
	t.n = 998;

	cout << "t.ch = " << t.ch << "  t.n = " << t.n << endl;

	return 0;
}

/*
run:

t.ch = z  t.n = 998

*/

 



answered Mar 17, 2018 by avibootz

Related questions

1 answer 91 views
91 views asked Nov 22, 2024 by avibootz
1 answer 176 views
176 views asked Dec 27, 2020 by avibootz
1 answer 157 views
157 views asked Mar 17, 2018 by avibootz
1 answer 229 views
1 answer 200 views
1 answer 161 views
161 views asked Mar 17, 2018 by avibootz
...