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. Questions about creating a 3D array class

Questions about creating a 3D array class

Scheduled Pinned Locked Moved C / C++ / MFC
c++designdata-structurestutorialquestion
2 Posts 2 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.
  • L Offline
    L Offline
    leileicats
    wrote on last edited by
    #1

    I am doing one project in the book "Data Structures and Algorithms with Object-Oriented Design Patterns in C++". The project is designing a 3D array class based on previous 2D array class. Code as follows: template class Array2D { public: Array2D(int w, int h):width(w), height(h), array(w*h) {} ... ... protected: int width, height; Array array; } template class Array3D { public: Array3D(int l, int w, int h):length(l), width(w), height(h), array(l) {} ... ... protected: int length, width, height; Array< Array2D > array; } I am planning to create a array with elements of 2D array. I could use the initializer "array(l)" to define the length of array. But the size of element "Array2D" should be "width*height". But I don't know how to initialize the size of "Array2D" in the class of Array3D. Could anybody give me some advice please?

    B 1 Reply Last reply
    0
    • L leileicats

      I am doing one project in the book "Data Structures and Algorithms with Object-Oriented Design Patterns in C++". The project is designing a 3D array class based on previous 2D array class. Code as follows: template class Array2D { public: Array2D(int w, int h):width(w), height(h), array(w*h) {} ... ... protected: int width, height; Array array; } template class Array3D { public: Array3D(int l, int w, int h):length(l), width(w), height(h), array(l) {} ... ... protected: int length, width, height; Array< Array2D > array; } I am planning to create a array with elements of 2D array. I could use the initializer "array(l)" to define the length of array. But the size of element "Array2D" should be "width*height". But I don't know how to initialize the size of "Array2D" in the class of Array3D. Could anybody give me some advice please?

      B Offline
      B Offline
      Branislav
      wrote on last edited by
      #2

      One solution can help you to make something new: class Array2D { public: Array2D(int w, int h):width(w), height(h), array(w*h) {} ... ... protected: int width, height; Array array; } template class Array3D :public Array2D { public: Array3D(int l, int w, int h) : Array2D( w, h), length(l) {} ... ... protected: int length; //Array< Array2D > array; }

      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