Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. A question about programming style

A question about programming style

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nguyenvhn
    wrote on last edited by
    #1

    Hi, In Visual Basic, when working with objects, we have the following syntax: obj.property=value or variable=obj.property call obj.method([params]) Remember that the property is not only member variable which is declared with public modifier but the property can (and in fact its always) be a function. So we do not need to know where to store value or where the data of variable come from inside the object. More over, function inside property allows us to do few calculations based on value set or got. My question here is: In Visual C, Could I implement such programming style, by any way? At present, I implement such style by declaration a member variable as public member, but it may not good when working with object. Implementation Set, Get functions do not allow VB programming style. Thanks for reading.

    G T 2 Replies Last reply
    0
    • N nguyenvhn

      Hi, In Visual Basic, when working with objects, we have the following syntax: obj.property=value or variable=obj.property call obj.method([params]) Remember that the property is not only member variable which is declared with public modifier but the property can (and in fact its always) be a function. So we do not need to know where to store value or where the data of variable come from inside the object. More over, function inside property allows us to do few calculations based on value set or got. My question here is: In Visual C, Could I implement such programming style, by any way? At present, I implement such style by declaration a member variable as public member, but it may not good when working with object. Implementation Set, Get functions do not allow VB programming style. Thanks for reading.

      G Offline
      G Offline
      gUrM33T
      wrote on last edited by
      #2

      Extracted from MSDN: **__declspec( property( get**=get_func_name **) )** declarator **__declspec( property( put**=put_func_name **) )** declarator **__declspec( property( get**=get_func_name, put=put_func_name **) )** declarator This attribute can be applied to non-static “virtual data members” in a class or structure definition. The compiler treats these “virtual data members” as data members by changing their references into function calls. When the compiler sees a data member declared with this attribute on the right of a member-selection operator (“.” or “->“), it converts the operation to a get or put function, depending on whether such an expression is an l-value or an r-value. In more complicated contexts, such as “+=“, a rewrite is performed by doing both get and put. This attribute can also be used in the declaration of an empty array in a class or structure definition. For example: __declspec(property(get=GetX, put=PutX)) int x[]; The above statement indicates that x[] can be used with one or more array indices. In this case, i=p->x[a][b] will be turned into i=p->GetX(a, b), and p->x[a][b] = i will be turned into p->PutX(a, b, i); Gurmeet S. Kochar


      If you believe in God, it's because of the Devil

      My CodeProject Articles: HTML Reader C++ Class Library, Numeric Edit Control

      N 1 Reply Last reply
      0
      • N nguyenvhn

        Hi, In Visual Basic, when working with objects, we have the following syntax: obj.property=value or variable=obj.property call obj.method([params]) Remember that the property is not only member variable which is declared with public modifier but the property can (and in fact its always) be a function. So we do not need to know where to store value or where the data of variable come from inside the object. More over, function inside property allows us to do few calculations based on value set or got. My question here is: In Visual C, Could I implement such programming style, by any way? At present, I implement such style by declaration a member variable as public member, but it may not good when working with object. Implementation Set, Get functions do not allow VB programming style. Thanks for reading.

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        be careful, OOP is NOT available in C (so either in Visual C). object programming comes with C++. And for your question, yes, you can. Classes are made for such. You put your data members eito private or protected statements (in general) as properties, and the interface for your classe, defined with your function members ("methods" in VB) are in a public statement. All of this is not definitive, but it is a cool way of programming properly.


        TOXCCT >>> GEII power

        1 Reply Last reply
        0
        • G gUrM33T

          Extracted from MSDN: **__declspec( property( get**=get_func_name **) )** declarator **__declspec( property( put**=put_func_name **) )** declarator **__declspec( property( get**=get_func_name, put=put_func_name **) )** declarator This attribute can be applied to non-static “virtual data members” in a class or structure definition. The compiler treats these “virtual data members” as data members by changing their references into function calls. When the compiler sees a data member declared with this attribute on the right of a member-selection operator (“.” or “->“), it converts the operation to a get or put function, depending on whether such an expression is an l-value or an r-value. In more complicated contexts, such as “+=“, a rewrite is performed by doing both get and put. This attribute can also be used in the declaration of an empty array in a class or structure definition. For example: __declspec(property(get=GetX, put=PutX)) int x[]; The above statement indicates that x[] can be used with one or more array indices. In this case, i=p->x[a][b] will be turned into i=p->GetX(a, b), and p->x[a][b] = i will be turned into p->PutX(a, b, i); Gurmeet S. Kochar


          If you believe in God, it's because of the Devil

          My CodeProject Articles: HTML Reader C++ Class Library, Numeric Edit Control

          N Offline
          N Offline
          nguyenvhn
          wrote on last edited by
          #4

          Thank you very much. Could you show me where to get that article in MSDN? I am using MSDN October 2001. But I did not find your article in its. I think your idea is very interesting.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups