implementing property in c++ just like c#?

This is a discussion on implementing property in c++ just like c#? within the C++ Programming forums, part of the General Programming Boards category; >> There is a problem with getters with the current C++ standard due to implicit conversion operators. They cause unwanted ...

  1. #16
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,739
    >> There is a problem with getters with the current C++ standard due to implicit conversion operators. They cause unwanted side effects.

    Are you sure that is a problem with getters and not just a problem in general? Because, for example, c_string() is a getter that is also an explicit conversion, and it is better than any C++03 alternative.

  2. #17
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,788
    Of course, I mean getters as in conversion operators, such as discussed in this thread. These conversion operators are a problem in general which is why we see member functions such as c_str() in the standard library.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    It just doesn't seem to be worth it.
    I am forced to agree with this. C++ offers many ways to achieve the same behavior. To be honest C# doesn't 'need' them either or at least I haven't found a 'need' for them. You could just as well create setters and getters in C#. But it is nice to be able to write this without any type of backing store needed:

    Code:
    public bool Visible { get; private set; }
    I can say that syntax is 100% better than the equivalent in C++. Sorry C++ but you lose this one to C# hands down.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. static property
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 06-12-2008, 01:03 AM
  2. C++/CLI Property
    By psychopath in forum Windows Programming
    Replies: 5
    Last Post: 07-11-2006, 09:45 PM
  3. Problem with a file parser.
    By Hulag in forum C++ Programming
    Replies: 7
    Last Post: 03-17-2005, 08:54 AM
  4. Dialog Box & Property Sheet :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2002, 01:33 PM
  5. Property Sheets :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 05-09-2002, 03:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21