Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Object properties in C++ - almost complete, but with sily problem

30 views
Skip to first unread message

Szyk Cech

unread,
May 30, 2019, 1:11:36 PM5/30/19
to
Hi
I trying to implement "properties" in C++ (similar to Dephi or C++
Builder). It is almost complete, but I have silly problem. Problem is
with automatic cast from Property class to property type class. This not
happen for every types - for example int works as expected. But
std::string fail for not reimplemented operators. I can overcome this
problem by:
static_cast<std::string&>(lObject.mStringProperty)
, but it is talkative and cumber some and I feel awful when I program
like this.
So, something like this not compile at all:

lObject.mStringProperty += std::string(" A to dopiero!!!"); // Failed
with g++

Error is:
/home/szyk/!-EnergoKod/!-Libs/EnergoKodProperty/Tests/Src/Main.cpp: In
function ‘int main()’:
/home/szyk/!-EnergoKod/!-Libs/EnergoKodProperty/Tests/Src/Main.cpp:81:29:
error: no match for ‘operator+=’ (operand types are
‘Property<WithProperties, std::__cxx11::basic_string<char> >’ and
‘std::__cxx11::string {aka std::__cxx11::basic_string<char>}’)
lObject.mStringProperty += std::string(" A to dopiero!!!"); //
Failed with g++
~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

But some thing like this:

lObject.mIntProperty += 1;

Works fine!

If you are interested and if you can help me please clone this tiny
Cmake project from github.com:

https://github.com/SzykCech4/EnergoKodProperty.git

Note: That project contain Tests subdir with test project - you should
enable BUILD_TESTS option in main CMakeLists.txt in order to compile
this simple test.

thanks in advance and best regards
Szyk Cech

Thiago Adams

unread,
May 30, 2019, 1:23:25 PM5/30/19
to
On Thursday, May 30, 2019 at 2:11:36 PM UTC-3, Szyk Cech wrote:
..
> If you are interested and if you can help me please clone this tiny
> Cmake project from github.com:

I did some experiments with properties in the past (November 2012)

http://thradams.com/properties2.htm

but this is just for fun, I don't recommend to use it.



Szyk Cech

unread,
May 30, 2019, 1:58:58 PM5/30/19
to
> http://thradams.com/properties2.htm

Very interesting! Thanks!

> but this is just for fun, I don't recommend to use it.

But what is wrong with this idea?!?

Szyk Cech

unread,
May 30, 2019, 2:08:52 PM5/30/19
to
I look for your implementation, and I doubt whether overload all
operators is desired. In standard (e.g. in Qt) properties we have just 3
functions: getter, setter and notifier. But with every possible
operators we have over dozen functions!

Thiago Adams

unread,
May 30, 2019, 2:26:50 PM5/30/19
to
If it is not part of the language It doesn't
follow the KISS principle.

If it was part of the language I think it would just add
more ways of doing something and C++ is already full of features.



Cholo Lennon

unread,
May 30, 2019, 11:43:23 PM5/30/19
to
I've already discussed Properties in VC++ newsgroup several years ago:

https://groups.google.com/d/msg/microsoft.public.dotnet.languages.vc/PbCL1PASfQc/hXNjaHDZ980J

Regards

--
Cholo Lennon
Bs.As.
ARG

0 new messages