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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. constructor and destructor [modified]

constructor and destructor [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 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.
  • Z Offline
    Z Offline
    zakria81
    wrote on last edited by
    #1

    Hi, how can I write the code for the constructor and destructor of this class class ThreeD{ public: ThreeD(int=5, int=5, int=5); ~ ThreeD( ); private: int *** data; int l, w, d; }; thank you

    modified on Thursday, March 25, 2010 10:50 PM

    H D 2 Replies Last reply
    0
    • Z zakria81

      Hi, how can I write the code for the constructor and destructor of this class class ThreeD{ public: ThreeD(int=5, int=5, int=5); ~ ThreeD( ); private: int *** data; int l, w, d; }; thank you

      modified on Thursday, March 25, 2010 10:50 PM

      H Offline
      H Offline
      hanq_38910130
      wrote on last edited by
      #2

      Actually, I think the design of your class "ThreeD" is terrible. If you are sure to implement it, the follow is for you. class ThreeD { public: ThreeD(int _l=5, int _w=5, int _d=5) : l(_l), w(_w), d(_d) { data = new int**[l]; for (int i=0; i<l; ++i) { data[i] = new int*[w]; for (int j=0; j<w; ++j) { data[i][j] = new int[d]; memset(data[i][j], 0, d*sizeof(int)); } } } ~ThreeD() { for (int i=0; i<l; ++i) { for (int j=0; j<w; ++j) { delete [] (data[i][j]); } delete [] (data[i]); } delete [] data; } private: int*** data; int l, w, d; };

      1 Reply Last reply
      0
      • Z zakria81

        Hi, how can I write the code for the constructor and destructor of this class class ThreeD{ public: ThreeD(int=5, int=5, int=5); ~ ThreeD( ); private: int *** data; int l, w, d; }; thank you

        modified on Thursday, March 25, 2010 10:50 PM

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        zakria81 wrote:

        Hi, how can I write the code for the constructor and destructor of this class

        Your question is vague at best. Given what little you've provided, you can implement them any way you wish. Have a look at the "How to ask a question" thread on the first page of this forum.

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "Man who follows car will be exhausted." - Confucius

        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