ReadOnly property on vc++ 2005  
Author Message
dedoz





PostPosted: Visual C++ Language, ReadOnly property on vc++ 2005 Top

Hi, im new in this forum and i dont speak english so please try to understand.

i wanna add a readonly property to a c++ class in a vc++2005 project. so i did this

public class someclass

{

private: int _x;

public: property int x {

int get() { return this->_x; }

}

}

and when i try to compile says "Error 3 error C3903: 'someclass::x': does not have set or get method"

so i think i need some word like "readonly" before "property" like in VB but i cant find the correct keyword, i was looking in inet, in the vs help and in this forums but cant find the answer. Thanks and sorry bout my bad english.



Visual C++16  
 
 
Alex Farber





PostPosted: Visual C++ Language, ReadOnly property on vc++ 2005 Top

Property syntax is used in managed classes (ref), and your class is native. In native unmanaged class use:
public:
int GetX() { return _x; }

 
 
dedoz





PostPosted: Visual C++ Language, ReadOnly property on vc++ 2005 Top

sorry i forgot to put "ref class" ... is a managed class ... is there a "readonly property" in managed classes like

public : readonly property int X {

int get() { return _x; }

}


 
 
Alex Farber





PostPosted: Visual C++ Language, ReadOnly property on vc++ 2005 Top

Readonly property is property which has only get method. Your original version is OK for managed class:

public ref class someclass
{
private: int _x;

public: property int x { int get() { return this->_x; } }
};