M
mario
Hi!
First of all, sorry for my English, it's not my native tongue.
Anyway, here we go:
suppose I create a class that handles my own custom text strings.
No, suppose I create TWO such classes, which differ e.g. in the
characters mappings and in the implementation, etc...
Necessary operators are overloaded, so that the following example
works as one may intuitively expect it to work:
MyFirstType MyFirstTypeInstanceA, MyFirstTypeInstanceB;
MySecondType MySecondTypeInstanceA,MySecondTypeInstanceB;
MyFirstTypeInstanceA=GetFirstTypeString();
MySecondTypeInstanceA=GetSecondTypeString();
MyFirstTypeInstanceB="Hello"+MyFirstTypeInstanceA+NewLine;
MySecondTypeInstanceB="Hello"+MySecondTypeInstanceA+NewLine;
Please focus on "NewLine". My problem is the following:
I want NewLine to be a *different* constant in the two cases
of above. The compiler knows, in the first case, that it is
evaluating an expression of type "MyFirstType" because it is
assigning the expression to an instance of that type. It also
knowns, in the second case, that this time it is evaluating
an expression of type MySecondType. So it has enough info to
understand that NewLine, if declared as constant, belongs to
its own class each time it evaluates a certain expression.
But I don't know if C++ allows this, hence this post of mine.
Sure, I could do something like:
MyFirstTypeInstanceA="Hello"+MyFirstType::NewLine;
MySecondTypeInstanceA="Hello"+MySecondType::NewLine;
(I made them shorter to avoid the 78 chars Usenet limitation)
But it seems awkward to me to have to specify the type before
the constant, when e.g. the "Hello" conversion from char to
the right type is automaticly handled in an nice way by the
compiler.
Is there any way in C++ to make a (preferably compile time,
for performance reasons) constant depend on the "context" (I
mean on the type that is being evaluated in the expression)?
Sorry again for my English, it's not my native language.
Thanks a lot,
Mario
First of all, sorry for my English, it's not my native tongue.
Anyway, here we go:
suppose I create a class that handles my own custom text strings.
No, suppose I create TWO such classes, which differ e.g. in the
characters mappings and in the implementation, etc...
Necessary operators are overloaded, so that the following example
works as one may intuitively expect it to work:
MyFirstType MyFirstTypeInstanceA, MyFirstTypeInstanceB;
MySecondType MySecondTypeInstanceA,MySecondTypeInstanceB;
MyFirstTypeInstanceA=GetFirstTypeString();
MySecondTypeInstanceA=GetSecondTypeString();
MyFirstTypeInstanceB="Hello"+MyFirstTypeInstanceA+NewLine;
MySecondTypeInstanceB="Hello"+MySecondTypeInstanceA+NewLine;
Please focus on "NewLine". My problem is the following:
I want NewLine to be a *different* constant in the two cases
of above. The compiler knows, in the first case, that it is
evaluating an expression of type "MyFirstType" because it is
assigning the expression to an instance of that type. It also
knowns, in the second case, that this time it is evaluating
an expression of type MySecondType. So it has enough info to
understand that NewLine, if declared as constant, belongs to
its own class each time it evaluates a certain expression.
But I don't know if C++ allows this, hence this post of mine.
Sure, I could do something like:
MyFirstTypeInstanceA="Hello"+MyFirstType::NewLine;
MySecondTypeInstanceA="Hello"+MySecondType::NewLine;
(I made them shorter to avoid the 78 chars Usenet limitation)
But it seems awkward to me to have to specify the type before
the constant, when e.g. the "Hello" conversion from char to
the right type is automaticly handled in an nice way by the
compiler.
Is there any way in C++ to make a (preferably compile time,
for performance reasons) constant depend on the "context" (I
mean on the type that is being evaluated in the expression)?
Sorry again for my English, it's not my native language.
Thanks a lot,
Mario