|
-
February 24th, 2011, 02:31 PM
#1
Question concerning property functions of templates
Hi together,
my problem is: I have a (managed) template class/structure with property functions like e.g.
template< typename T1 >
public ref struct MyStruct
{
typedef T1 given_type;
...
private:
T1 _element;
public:
property given_type element
{
given_type get() { return _element; }
void set(given_type val) { _element = val; }
}
...
};
It works fine, unless I use a const template parameter like:
MyStruct< const System::Int32 > my;
In this case, the compiler complains about the set function because when T1 is const then the value of _element isn't allowed to change (which is quite right).
Therefore I'm looking for a solution to distinct between const and non-const template parameters. In the case of const parameters I don't want to have the set function.
As a solution I could declare specializations for the whole structure but my real case is much more complicate than the artificial example above and therefore I don't like this solution.
Is there any other solution to solve this problem?
Many thanks in advance,
Physicus.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|