properties
-
hello, i was wondering if there is an equivalent of the c# feature "properties" in c++. i.e., the client sees it as a variable, but methods are called to access it. You should understand from this c# sample:
// test.cs namespace MyApp { public class TestClass { private int _item; TestClass(int tmp) { _item = tmp; } public int data { get {return _item;} set {_item = value;} // 'value' is implicitly the value // being assigned to the property } static void Main() { TestClass x = new TestClass(17); int res = TestClass.data; // res is now 17 TestClass.data = 42; res = TestClass.data; // res is now 42 } } }
any equivalient in c++ ? -
hello, i was wondering if there is an equivalent of the c# feature "properties" in c++. i.e., the client sees it as a variable, but methods are called to access it. You should understand from this c# sample:
// test.cs namespace MyApp { public class TestClass { private int _item; TestClass(int tmp) { _item = tmp; } public int data { get {return _item;} set {_item = value;} // 'value' is implicitly the value // being assigned to the property } static void Main() { TestClass x = new TestClass(17); int res = TestClass.data; // res is now 17 TestClass.data = 42; res = TestClass.data; // res is now 42 } } }
any equivalient in c++ ?No. Properties do not exist in C++. Christian Graus - Microsoft MVP - C++