I have a class like this:
public ref class Test
{
public:
property int MyProperty;
};
This works. Now I want to move the implementation of MyProperty to the CPP file. I get compiler errors that the property is already defined when I do this:
int Test::MyProperty::get() { return 0; }
What is the proper syntax for this?
In the header change the declaration to:
public ref class Test
{
public:
property int MyProperty
{
int get();
void set( int );
}
private:
int m_myProperty;
};
Then, in the cpp code file write your definitions like this:
int Test::MyProperty::get()
{
return m_myProperty;
}
void Test::MyProperty::set( int i )
{
m_myProperty = i;
}
The reason you are seeing errors is that you have declared a trivial property where the compiler generates an implementation for you. But, then you tried to provide an implementation explicitly as well. See: http://msdn.microsoft.com/en-us/library/windows/apps/hh755807(v=vs.110).aspx
Most of the examples online only show implementations directly in the class definition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With