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. How to create a vector?

How to create a vector?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicstutorialquestion
4 Posts 3 Posters 1 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.
  • D Offline
    D Offline
    deadlyabbas
    wrote on last edited by
    #1

    Hi All, I have a member variable of data type double. Following is the variable double m_Value [7] [3]; Now I have to do the declaration by using vectors. so how I will declare it. I have to Initialize it by 0 also.......... Thanks

    J 1 Reply Last reply
    0
    • D deadlyabbas

      Hi All, I have a member variable of data type double. Following is the variable double m_Value [7] [3]; Now I have to do the declaration by using vectors. so how I will declare it. I have to Initialize it by 0 also.......... Thanks

      J Offline
      J Offline
      Jijo Raj
      wrote on last edited by
      #2

      Hi deadlyabbas,

      const int ROW = 7; // Row
      const int COLUMN = 3; // Column

      // same as - double m_Value [7] [3]; initialized with 0.0
      // vector can be initialized by - vector<type>( size, DefaultValue );
      vector< vector<double> > m_Value( ROW, vector<double>( COLUMN, 0.0 ));

      Best Regards, Jijo.

      _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

      D 1 Reply Last reply
      0
      • J Jijo Raj

        Hi deadlyabbas,

        const int ROW = 7; // Row
        const int COLUMN = 3; // Column

        // same as - double m_Value [7] [3]; initialized with 0.0
        // vector can be initialized by - vector<type>( size, DefaultValue );
        vector< vector<double> > m_Value( ROW, vector<double>( COLUMN, 0.0 ));

        Best Regards, Jijo.

        _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

        D Offline
        D Offline
        deadlyabbas
        wrote on last edited by
        #3

        Thanks Jijo. But the issue with this is that I am not able to make declaration and definition separately. If I do it like this in .h file

        vector> m_Value;

        and in .cpp file I do this

        m_value(10,vector(3,0.0));

        It gave me an error which says error C2064: term does not evaluate to a function taking 2 arguments

        _ 1 Reply Last reply
        0
        • D deadlyabbas

          Thanks Jijo. But the issue with this is that I am not able to make declaration and definition separately. If I do it like this in .h file

          vector> m_Value;

          and in .cpp file I do this

          m_value(10,vector(3,0.0));

          It gave me an error which says error C2064: term does not evaluate to a function taking 2 arguments

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          You should be able to do this using the constructor initialization list. MyClass.h file

          class CMyClass
          {
          private:
          vector< vector<double> > m_Value;
          };

          MyClass.cpp

          CMyClass::CMyClass() : m_Value(ROW, vector<double>( COLUMN, 0.0 ))
          {
          }

          «_Superman_» I love work. It gives me something to do between weekends.
          Microsoft MVP (Visual C++)

          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