How to use class name to access field name in C++

1 Answer

0 votes
#include <iostream>

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

class Test {
	float price;
public:
	Test(float p) : price(p) { }
	void show(void);
};

void Test::show(void)
{
	cout << Test::price << endl;
}
int main()
{
	Test o(38.95);
	
	o.show();
	
	return 0;
}

/*
run:

38.95

*/

 



answered Mar 19, 2018 by avibootz

Related questions

...