Vector
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Vector

  1. #1
    Join Date
    Mar 2007
    Posts
    238

    Vector

    HI All,
    I need some help in creating and accessing vector.
    I have a class...
    Class CMyPage{
    MyPage::MyPage(Cstring strfilename, LONGLONG liEditpoint):
    m_filename(strfilename)
    ,m_liEdit(liEditpoint)
    {
    }

    Get FileName(return m_filename
    Get EditPoint(return liEdit

    private:
    CString m_filename;
    LONGLONG m_liEdit;


    };

    I will be creating a vector of this class as I need to increase at run time.
    Class 2{
    private:
    std::vector<CMyPage> vecMyPage;


    local function{
    CString filename = "dkljfdkfj";
    LONGLONG ni = < some number>;

    CMyPage mypage(filename, ni);
    vecMyPage.pushback(mypage);
    }

    It all works fine when i call this function 2 times. If it's called more, then the previous value in the vector(only the CString) become null or some rubbish character. How do I make sure the value does not go out of scope?

    Thanks for any help.

    P.S: the code is there just to give an idea of what i am trying to do. Hope you appreciate that my question here is more logical or understanding the concept.

  2. #2
    Join Date
    Mar 2007
    Posts
    238

    Re: Vector

    Managed to find out that the string value is going out of scope because its a LPCTSTR. I used CString and it worked !!

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,605

    Re: Vector

    Quote Originally Posted by tarunk View Post
    I have a class...
    Code:
    Class CMyPage{
      MyPage::MyPage(Cstring strfilename, LONGLONG liEditpoint):
        m_filename(strfilename)
        ,m_liEdit(liEditpoint)
        {
        }
    what is MyPage?

    And if you really have a problem with your code then please show your actual code (using Code tags of course).
    Otherwise you'll get "pseudo"-answers on your pseudo-code.
    Victor Nijegorodov

  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,594

    Re: Vector

    Just to add...

    Quote Originally Posted by tarunk View Post
    Managed to find out that the string value is going out of scope because its a LPCTSTR. I used CString and it worked !!
    Interesting. The identifier LPCTSTR doesn't occur even a single time in the "code" you posted.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center