__property on unmanaged class

A

Adriano Coser

Hello.

I´m evaluating Visual C++ .NET and I'm trying to convert a program
developed with Borland C++ Builder. In this program I use the
__property keyword on the definition of my classes.

Writing managed code I could easily translate the properties
declarations to mantain their uses. But I'm not writing managed code,
I want to keep my non-interface classes unmanaged. Is there a way to
translate the VCL style properties do unmanaged Visual C++ mantaining
the syntax "student->Age = 31;" ?

Thanks in advance for any help.

Regards,
Adriano.
 
J

Jeroen Smits

Hmm, after 2 years of C# my C++ is a bit rusty, but I remember something
like:

__declspec( property( get=getAge, put=setAge ) ) int Age;
int getAge() { return <codeToReturnAge>; }
void setAge( int age ) { <codeToSetAge>; }
 
T

TOM

Maybe I misunderstand the question, but is it as simple as
making 'Age' a public: member of the class?

-- Tom
 
G

Georgescu Aurelian

Hello,

just try this:

class CMyClass
{
public:

__declspec( property( get = get_Age, put = put_Age ) ) int Age;

public:
void put_Age(int age)
{
m_nAge = age;
}

int get_Age()
{
return m_nAge;
}

private:
int m_nAge;
};

Best regards,
Relu.
 
A

Adriano Coser

Is there a way to specify a protected/private variable or member
function for a property?

All my C++ Builder implementation is on this way, the returned
variables are always protected or private, to avoid direct access.

Eg:

public:
__declspec( property( get = age, put = SetAge ) ) int Age;

private:
int age;

void SetAge(int _age) { age = _age; }

If I do this on Visual C, I got a compiler error accessing the
property, as if I was trying to access the variable/method directly.

Thanks,
Adriano.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top