Implementing properties in an unmanaged class (in a managed project)

M

Mark Ingram

Hi, can anyone tell me why I'm getting the following error:



error C4980: '__property' : use of this keyword requires /clr:blush:ldSyntax
command line option
&
error C3813: a property declaration can only appear within the
definition of a managed type



Here is my code:

#pragma once

#pragma unmanaged

class WaveformData
{
public:

__property __int64 get_TotalSamples() { return m_totalSamples; }
__property void set_TotalSamples(__int64 value) { m_totalSamples =
value; }

__property int* get_SampleStart() { return m_sampleStart; }
__property void set_SampleStart(int* value) { m_sampleStart = value; }

__property int* get_SampleEnd() { return m_sampleEnd; }
__property void set_SampleEnd(int* value) { m_sampleEnd = value; }

__property __int64 get_TimelineTime() { return m_timelineTime; }
__property void set_TimelineTime(__int64 value) { m_timelineTime =
value; }

__property int get_Pixels() { return m_pixels; }
__property void set_Pixels(int value) { m_pixels = value; }

private:
__int64 m_totalSamples;
int* m_sampleStart;
int* m_sampleEnd;
__int64 m_timelineTime;
int m_pixels;
};

#pragma managed


I could do this previously in .NET 1.1 (and any unmanaged projects)

Has the syntax changed for basic c++ classes?

Thanks,
 
B

Bruno van Dooren [MVP VC++]

error C4980: '__property' : use of this keyword requires /clr:blush:ldSyntax
command line option
&
error C3813: a property declaration can only appear within the definition
of a managed type

properties are a .NET concept.
Defining a property for an unmanaged class is not possible AFAIK.
Unmanaged code has only 2 things you can use:
- public variables
- get and set methods.

I did not think this would work in previous versions, but -and I am on a
limb here- I suspect it was allowed because Managed Extensions for C++ was
designed as an extension within the language, whereas C++/CLI is a language
add-on.
Despite using the old syntax, you would still be using C++/CLI.
But I could be wrong.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
M

Mark Ingram

Bruno said:
properties are a .NET concept.
Defining a property for an unmanaged class is not possible AFAIK.
Unmanaged code has only 2 things you can use:
- public variables
- get and set methods.

I did not think this would work in previous versions, but -and I am on a
limb here- I suspect it was allowed because Managed Extensions for C++ was
designed as an extension within the language, whereas C++/CLI is a language
add-on.
Despite using the old syntax, you would still be using C++/CLI.
But I could be wrong.

__property was a Microsoft specific keyword for defining properties in
standard c++ classes. I can only assume they removed it to be more
compliant with the c++ standard?

Ahh, I've just realised that the code I was typing was incorrect, and it
should be like this:

__declspec(property(get = GetName, put = SetName )) LPCTSTR
Name;

Thanks,
 

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