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. Really Silly Question I Think

Really Silly Question I Think

Scheduled Pinned Locked Moved C / C++ / MFC
c++questiongraphicshelp
8 Posts 6 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.
  • W Offline
    W Offline
    William Bartholomew
    wrote on last edited by
    #1

    I'm relatively new to C++ programming which i'm sure this question will demonstrate... I want to use vector's in an MFC dialog application that AppWizard generated for me, I added #include but when I declare vector vTest; I get an error saying that the type is not found... So I tried adding a "using namespace std;" and it said it can't find the namespace std... What am I doing wrong??? :confused: Thanks, William

    C K 2 Replies Last reply
    0
    • W William Bartholomew

      I'm relatively new to C++ programming which i'm sure this question will demonstrate... I want to use vector's in an MFC dialog application that AppWizard generated for me, I added #include but when I declare vector vTest; I get an error saying that the type is not found... So I tried adding a "using namespace std;" and it said it can't find the namespace std... What am I doing wrong??? :confused: Thanks, William

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Let me start by saying congratulations for using the STL. I was not so smart when I was starting and am only learning it now. A vector, like any array, needs to know what it is going to hold. I don't know if you're familair with templates, but they essentially allow you to specify a type as a parameter. To specify a vector of int's, you must do this: vector m_MyIntVector; Having #included vector, you can remove using namespace std if you want to. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

      V 1 Reply Last reply
      0
      • C Christian Graus

        Let me start by saying congratulations for using the STL. I was not so smart when I was starting and am only learning it now. A vector, like any array, needs to know what it is going to hold. I don't know if you're familair with templates, but they essentially allow you to specify a type as a parameter. To specify a vector of int's, you must do this: vector m_MyIntVector; Having #included vector, you can remove using namespace std if you want to. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

        V Offline
        V Offline
        Vivek Rajan
        wrote on last edited by
        #3

        Ok - You have to say what the vector is going to hold. So, vector myVector; // Will not work.. Try using; vector myVector; vector myVector; vector myVector; ...etc I am going to venture a guess you are coming from Java-land, where you just say Vector myVector; then you can stick anything in there.. STL is more type safe than Java containers.. Good luck Vivke

        V 1 Reply Last reply
        0
        • W William Bartholomew

          I'm relatively new to C++ programming which i'm sure this question will demonstrate... I want to use vector's in an MFC dialog application that AppWizard generated for me, I added #include but when I declare vector vTest; I get an error saying that the type is not found... So I tried adding a "using namespace std;" and it said it can't find the namespace std... What am I doing wrong??? :confused: Thanks, William

          K Offline
          K Offline
          kvk123
          wrote on last edited by
          #4

          When U are using the MFC there are lot many classes are there which gives the functionality of vector. Carray, CList, SafeArray like somay classes are there. U can Initiliza the classes and use it directly in your program. If you are not using MFC then inclede all the std header files. :)

          A 1 Reply Last reply
          0
          • V Vivek Rajan

            Ok - You have to say what the vector is going to hold. So, vector myVector; // Will not work.. Try using; vector myVector; vector myVector; vector myVector; ...etc I am going to venture a guess you are coming from Java-land, where you just say Vector myVector; then you can stick anything in there.. STL is more type safe than Java containers.. Good luck Vivke

            V Offline
            V Offline
            Vivek Rajan
            wrote on last edited by
            #5

            DUH - I knew Christian coulndt have overlooked the < int > in the template.. I didnt realize I was writing HTML in the post window. (Definitely confusing) Anyway, here goes.. Use; vector < int > ; or vector < float * > etc.. Tips , use the > and < for the < and > signs

            A 1 Reply Last reply
            0
            • V Vivek Rajan

              DUH - I knew Christian coulndt have overlooked the < int > in the template.. I didnt realize I was writing HTML in the post window. (Definitely confusing) Anyway, here goes.. Use; vector < int > ; or vector < float * > etc.. Tips , use the > and < for the < and > signs

              A Offline
              A Offline
              Alex Taylor
              wrote on last edited by
              #6

              Duh - that gets me every time. I obviously didn't look at my post. < > (just testing) Christian who just swapped PC's with Taylor

              1 Reply Last reply
              0
              • K kvk123

                When U are using the MFC there are lot many classes are there which gives the functionality of vector. Carray, CList, SafeArray like somay classes are there. U can Initiliza the classes and use it directly in your program. If you are not using MFC then inclede all the std header files. :)

                A Offline
                A Offline
                Alex Taylor
                wrote on last edited by
                #7

                When U are using the MFC there are lot many classes are there which gives the functionality of vector. I realise that there are people here who do not speak English as a first language, but fair dinkum - 'there are a lot many classes are there' ??? 'like somay classes are there' ??? 'Initiliza' ??? Carray, CList, SafeArray like somay classes are there. U can Initiliza the classes and use it directly in your program. If you are not using MFC then inclede all the std header files. To use CArray ( which is the same as a vector in it's O notation behaviour ( STL is defined in terms of O notation - vector was obviously meant to be an array, but it does not HAVE to be if someone comes up with a better idea )) you need to use tempplate arguments, you actually need to specify two rather than one. CList impliments a list, like deque. A list has totally different behaviour to an array in terms of speed ( quicker to remove items in the middle, slower to find them ). If you are not using MFC then you do not have CArray/CList/CSafeArray, unless there are alternate versions in the ATL headers. Either way, the STL is more powerful, more flexible and cross platform. I recommend you use the MFC classes for the sake of learning them, but stick to STL. I also recommend you write your own list and array class, just to get a good idea of what goes on under the hood, but still use STL. I recommend the person who wrote this reply also learn the difference between container types and consider learning the STL. Christian logged in as Alex

                T 1 Reply Last reply
                0
                • A Alex Taylor

                  When U are using the MFC there are lot many classes are there which gives the functionality of vector. I realise that there are people here who do not speak English as a first language, but fair dinkum - 'there are a lot many classes are there' ??? 'like somay classes are there' ??? 'Initiliza' ??? Carray, CList, SafeArray like somay classes are there. U can Initiliza the classes and use it directly in your program. If you are not using MFC then inclede all the std header files. To use CArray ( which is the same as a vector in it's O notation behaviour ( STL is defined in terms of O notation - vector was obviously meant to be an array, but it does not HAVE to be if someone comes up with a better idea )) you need to use tempplate arguments, you actually need to specify two rather than one. CList impliments a list, like deque. A list has totally different behaviour to an array in terms of speed ( quicker to remove items in the middle, slower to find them ). If you are not using MFC then you do not have CArray/CList/CSafeArray, unless there are alternate versions in the ATL headers. Either way, the STL is more powerful, more flexible and cross platform. I recommend you use the MFC classes for the sake of learning them, but stick to STL. I also recommend you write your own list and array class, just to get a good idea of what goes on under the hood, but still use STL. I recommend the person who wrote this reply also learn the difference between container types and consider learning the STL. Christian logged in as Alex

                  T Offline
                  T Offline
                  Tomasz Sowinski
                  wrote on last edited by
                  #8

                  > U can Initiliza the classes Looks like gangsta rap ;P Tomasz Sowinski -- http://www.shooltz.com.pl

                  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