1

Topic: Friday get

At MS there was such inconvenient piece, declspec (property) which allowed to get an alias for a variable to which have been anchored set and get.
As get normally piece simple I found for myself to do so:

publuc:
const CType& Type = m_type;
private:
CType m_type = 0;

Who does that think on it?

2

Re: Friday get

CEMb;
Would show as it works, and that without half-liters here explicitly will not understand

3

Re: Friday get

kealon (Ruslan) wrote:

would show as it works, and that without half-liters here explicitly you will not understand

I so understand speech about readonly access to Type

publuc:
>>> const <<<CType&>>> Type <<<= m_type;

4

Re: Friday get

CEMb;
const_cast' It is possible to bypass read-only protection.
If strongly it would be desirable, it is possible to get template class Property and to redefine at it operator = () and operator T () to which in the designer can transfer ljambdy-aksessory which will be caused in these operators. To  a sisjarpa/python far.

5

Re: Friday get

Dima T,
Now understood, I grow old probably
NekZ;
The abstraction is simply necessary to it what "not to fly". It is clear to eat bypasss always, the main thing that they would be "visible"

6

Re: Friday get

NekZ wrote:

const_cast' it is possible to bypass read-only protection.

matter is not in protection, business in automatics and convenience that I by mistake did not write in the code:

Type = sometype;

and thus it would be not necessary to write:

sometype = GetType ();

NekZ wrote:

If strongly it would be desirable, it is possible to get template class Property

And so I too do, but at this construction a little other sense.

NekZ wrote:

To  a sisjarpa/python far.

and than they so are unique?

7

Re: Friday get

CEMb, I and did not understand - that you want.

8

Re: Friday get

rdb_dev, I want a variable, which:
1. It is possible to write-read in a class and-or class hierarchy
2. It is possible to read only out of a class and-or class hierarchy
I.e. more simple (syntactically and on the code) analog get-a. The Read-only-representative of a variable outside.
Well and it, as though, a topic about research of approaches to the decision of such or similar tasks [img=http://www.sql.ru/forum/images/happy.gif]

9

Re: Friday get

CEMb wrote:

matter is not in protection, business in automatics and convenience that I by mistake did not write in the code:

Type = sometype;

and thus it would be not necessary to write:

sometype = GetType ();

Difficult, not .

CEMb wrote:

it is passed...
And than they so are unique?

Are unique that they already are in the grammar of language out-of-the-box, and also they have more possibilities for creation DSL.

10

Re: Friday get

CEMb, to me  as if I already showed you a similar method:

struct CType
{
struct SET;
private:
DWORD m;
friend struct SET;
public:
operator long ()
{return *reinterpret_cast <long *> (&this->m);}
operator unsigned long ()
{return *reinterpret_cast <unsigned long *> (&this->m);}
struct SET
{
private:
operator CType& ();
public:
CType& operator = (long src)
{
CType AND t = (CType&) (*this);
*reinterpret_cast <long *> (&t.m) = src;
return t;
}
CType& operator = (unsigned long src)
{
CType AND t = (CType&) (*this);
*reinterpret_cast <unsigned long *> (&t.m) = src;
return t;
}
}
set;
};
CType:: SET:: operator CType& ()
{
constexpr size_t set_offset = (size_t) &reinterpret_cast<CType*> (0)-> set;
return *reinterpret_cast <CType *> ((size_t) this - set_offset);
}
#pragma argsused
int __ cdecl main (int argc, char* argv [])
{
CType c;
c.set = 0xFFFFFFFFUL;
printf ("c = %i", (long) c);
return 0;
}

11

Re: Friday get

Naturally, it is possible and so:

#pragma argsused
int __ cdecl main (int argc, char* argv [])
{
CType c;
printf ("c = %i", (long) (c.set = 0xFFFFFFFFUL));
return 0;
}

12

Re: Friday get

NekZ wrote:

Are unique that they already are in the grammar of language out-of-the-box, and also they have more possibilities for creation DSL.

and what they was specific are able, in what advantage before a C ++?

rdb_dev wrote:

CEMb, me  as if I already showed you a similar method:

the Interesting variant, but it is a little perpendicular to about what I spoke. And in addition, it set, instead of get. And at you there pair  with which it would be possible to replace with sample function? And here the last operator to me is not clear. Well, i.e. it is clear that the pointer on parent structure is calculated on offset. And it is reliable? Whether is easier somehow in the designer in SET to transfer the pointer/reference at once?

13

Re: Friday get

CEMb wrote:

and what they was specific are able, in what advantage before a C ++?

Yes at least the same  in  and creation of new types "on the fly".

14

Re: Friday get

CEMb wrote:

the Interesting variant, but it is a little perpendicular to about what I spoke. And in addition, it set, instead of get.

there and set is... Get accustomed more attentively! It in the separate incapsulated structure.

CEMb wrote:

And at you there pair  with which it would be possible to replace with sample function?

Yes, certainly it is possible.

CEMb wrote:

And here the last operator to me is not clear. Well, i.e. it is clear that the pointer on parent structure is calculated on offset. And it is reliable?

Certainly it is reliable! A normal taking of the address and arithmetics of pointers... No access to storage on dereferencing of the pointer leading so-called to "indefinite behavior" here is present.

15

Re: Friday get

rdb_dev wrote:

There and set is... Get accustomed more attentively! It in the separate incapsulated structure.

, that's it, I told Nene about get only. And I told about a separate variable in a class, and at you an example about operation with a class through set.

16

Re: Friday get

CEMb wrote:

, that's it, I told Nene about get only. And I told about a separate variable in a class, and at you an example about operation with a class through set.

So adapt an example under the task. ... Simply I so precisely also did not understand, what exactly, as a result, you want to receive and did not make how you want. smile

17

Re: Friday get

rdb_dev wrote:

So adapt an example under the task. ...

so my decision in one line...

rdb_dev wrote:

I am simple so precisely and did not understand, what exactly, as a result, you want to receive and did not make how you want. smile

I wanted to make the simple mechanism for read-only that from the outside it was possible to read a variable, but it is impossible to write. I made the constant link to the closed variable, i.e. the class can work from a variable, and  can read only it through the link. And I wanted to learn, whether was not present where an error in my decision?

18

Re: Friday get

CEMb;
Unique minus which I see - the additional pointer in everyone  of this kind.
For large types it not a problem and if the type small also consists of pair  their size grows on third (and even in half).
And if such  one million it is 4 (8) MB of additional storage.
And the compiler has no right to throw out this field though will not use it, most likely.

19

Re: Friday get

Well and personally for me is a defining minus. I consider what to keep in the memory the senseless data it is impossible, it raises entropy and approaches thermal death of the Universe

20

Re: Friday get

rdb_dev wrote:

I am simple so precisely and did not understand, what exactly, as a result, you want to receive and did not make how you want. smile

I wanted to make the simple mechanism for read-only that from the outside it was possible to read a variable, but it is impossible to write. I made the constant link to the closed variable, i.e. the class can work from a variable, and  can read only it through the link. And I wanted to learn, whether was not present where an error in my decision?

Only? I thought... smile