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. constructor, is there any ambiguity ?

constructor, is there any ambiguity ?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondatabase
6 Posts 4 Posters 2 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.
  • U Offline
    U Offline
    User 1017986
    wrote on last edited by
    #1

    class a{ public: a():rs(&db) {} CRecordset rs;//line a CDatabase db; //line b }; // my question is shld line b comes before line a

    T R 2 Replies Last reply
    0
    • U User 1017986

      class a{ public: a():rs(&db) {} CRecordset rs;//line a CDatabase db; //line b }; // my question is shld line b comes before line a

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

      heu, you are trying to create an object, but you assign a member with another member of the same object, which wasn't set yet. so change your code... i'd like to add a remark. your code is note very beautiful, and worse, it is not very useful. put your data members in private statement, write your class definition in a .h file, and write the class implementation into a .cpp file :

      A.h
      class CA {
      CRecordset rs;
      CDatabase db;
      public:
      CA (void);
      //...
      }

      A.cpp
      CA::CA(void) : rs(), db() {
      }
      //...


      TOXCCT >>> GEII power

      2 1 Reply Last reply
      0
      • T toxcct

        heu, you are trying to create an object, but you assign a member with another member of the same object, which wasn't set yet. so change your code... i'd like to add a remark. your code is note very beautiful, and worse, it is not very useful. put your data members in private statement, write your class definition in a .h file, and write the class implementation into a .cpp file :

        A.h
        class CA {
        CRecordset rs;
        CDatabase db;
        public:
        CA (void);
        //...
        }

        A.cpp
        CA::CA(void) : rs(), db() {
        }
        //...


        TOXCCT >>> GEII power

        2 Offline
        2 Offline
        224917
        wrote on last edited by
        #3

        i feel that was the most simple way to express his doubt. It'd be funny to have .cpp and .h files along for such a simple question.


        It's not a bug, it's an undocumented feature.
        suhredayan@omniquad.com

        messenger :suhredayan@hotmail.com

        T 1 Reply Last reply
        0
        • 2 224917

          i feel that was the most simple way to express his doubt. It'd be funny to have .cpp and .h files along for such a simple question.


          It's not a bug, it's an undocumented feature.
          suhredayan@omniquad.com

          messenger :suhredayan@hotmail.com

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

          anyway, his code was wrong ! and you, i'm waiting for your response at your "who's who" page... :-D thx


          TOXCCT >>> GEII power

          2 1 Reply Last reply
          0
          • T toxcct

            anyway, his code was wrong ! and you, i'm waiting for your response at your "who's who" page... :-D thx


            TOXCCT >>> GEII power

            2 Offline
            2 Offline
            224917
            wrote on last edited by
            #5

            check out, its there!! ;)


            It's not a bug, it's an undocumented feature.
            suhredayan@omniquad.com

            messenger :suhredayan@hotmail.com

            1 Reply Last reply
            0
            • U User 1017986

              class a{ public: a():rs(&db) {} CRecordset rs;//line a CDatabase db; //line b }; // my question is shld line b comes before line a

              R Offline
              R Offline
              Robert A T Kaldy
              wrote on last edited by
              #6

              Members of class are constructed in order, in which are declared. It doesn't depend on, whether they are initialized in class constructor. And it also doesn't depend on the order of member initializers in class constructor. So in your example the line b should be before the line a. Robert-Antonio "Life is very hard, if you apply E-R model to it."

              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