vector of vectors containing classes

This is a discussion on vector of vectors containing classes within the C++ Programming forums, part of the General Programming Boards category; Hello, I am trying to make a matrix cointaining instances of a class. I made a simple class Code: class ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Location
    Barcelona
    Posts
    41

    vector of vectors containing classes

    Hello,
    I am trying to make a matrix cointaining instances of a class. I made a simple class
    Code:
    class POINT
    {
    	public:
    	double X;
    	double Y;
    	double Z;
    };
    Now I would like load instances of this class into a matrix. I am thinking I should use a vector of vectors, but I am not entirely sure. I am new to this and stuck, anybody?
    Code:
    vector<vector<POINT> > *dtm;
    Best regards

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    You can use a vector of vectors, but why a pointer?

    Also, vector of vectors is not very nice for a matrix because the sub-matrices could end up with different sizes. My preferred solution is Boost.MultiArray.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Jul 2008
    Location
    Barcelona
    Posts
    41
    Thanks for your reply and your tip. However I would like too stick with vectors.
    The pointer is there because I not sure what I am doing. My question is more how do I load my class instances into the vectors?
    Should I
    Code:
    vector<vector<POINT> > dtm;
    or
    Code:
    vector<vector<int> > *dtm;
    POINT *dtm;
    This is where I am lost.
    Cheers

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Well, first you should probably resize all vectors to match your desired matrix size. Then you simply use index syntax.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vectors of classes
    By Dondrei in forum C++ Programming
    Replies: 26
    Last Post: 03-20-2009, 06:11 AM
  2. classes and vectors
    By izuael in forum C++ Programming
    Replies: 10
    Last Post: 11-27-2006, 04:19 PM
  3. Vectors and custom classes
    By cunnus88 in forum C++ Programming
    Replies: 16
    Last Post: 05-12-2006, 06:11 AM
  4. vectors and classes
    By jimothygu in forum C++ Programming
    Replies: 3
    Last Post: 04-27-2003, 08:53 PM
  5. How To use vectors for custom classes
    By johnnyd in forum C++ Programming
    Replies: 14
    Last Post: 03-25-2003, 10:04 PM

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