Click here to Skip to main content
15,915,770 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: STL vs. MFC Pin
valikac7-Jan-03 4:43
valikac7-Jan-03 4:43 
GeneralRe: STL vs. MFC Pin
lpvoid7-Jan-03 5:48
lpvoid7-Jan-03 5:48 
GeneralRe: STL vs. MFC Pin
valikac7-Jan-03 9:02
valikac7-Jan-03 9:02 
GeneralRe: STL vs. MFC Pin
User 98858-Jan-03 10:06
User 98858-Jan-03 10:06 
GeneralRe: STL vs. MFC Pin
User 98859-Jan-03 2:36
User 98859-Jan-03 2:36 
GeneralRe: STL vs. MFC Pin
Tim Smith9-Jan-03 4:04
Tim Smith9-Jan-03 4:04 
GeneralRe: STL vs. MFC Pin
User 98859-Jan-03 5:12
User 98859-Jan-03 5:12 
GeneralRe: STL vs. MFC Pin
Tim Smith9-Jan-03 15:08
Tim Smith9-Jan-03 15:08 
Using vector the way you talk about won't work since the destination objects have not been constructed. This normally isn't a problem for things such as int. But for a complicated class where you override the copy operator, the copy operator would have expected the destination to have been constructed. Using reserve and then accessing the elements through a pointer won't work properly.

This program shows why it doesn't work.

#include <assert.h>
#include <vector>

class test
{
public:
    test ()
    {
        m_nInit = 1234567;
    }

    const test &operator = (const test &src)
    {
        //this instance should have been constructed
        assert (m_nInit == 1234567);
        m_nInit = src .m_nInit;
        return *this;
    }

    int m_nInit;
};

int main(int argc, char* argv[])
{
    std::vector <test> v;

    v .reserve (100);
    test *p = &v [0];
    p [0] = test ();
    return 0;
}


Also, the size of the vector is never set. Thus "size" will always return 0 so the vector thinks it is empty. Doing a push_back will destroy the first element of the vector you just tried to initialize.

As for the other stuff. That is basically what I said. CArray lacks a reserve.

Tim Smith

I'm going to patent thought. I have yet to see any prior art.
GeneralRe: STL vs. MFC Pin
lpvoid10-Jan-03 13:45
lpvoid10-Jan-03 13:45 
GeneralRe: STL vs. MFC Pin
lpvoid10-Jan-03 16:48
lpvoid10-Jan-03 16:48 
GeneralHelp with ATL 7.0 Pin
Binky6-Jan-03 8:12
Binky6-Jan-03 8:12 
Generalmap of _variant_t Pin
[James Pullicino]5-Jan-03 21:57
[James Pullicino]5-Jan-03 21:57 
GeneralRe: map of _variant_t Pin
Michael Dunn5-Jan-03 22:14
sitebuilderMichael Dunn5-Jan-03 22:14 
GeneralRe: map of _variant_t Pin
[James Pullicino]5-Jan-03 22:20
[James Pullicino]5-Jan-03 22:20 
GeneralRe: map of _variant_t Pin
Jörgen Sigvardsson17-Jan-03 12:26
Jörgen Sigvardsson17-Jan-03 12:26 
GeneralProblem with WTL Pin
Ph@ntom5-Jan-03 18:43
Ph@ntom5-Jan-03 18:43 
GeneralRe: Problem with WTL Pin
Michael Dunn5-Jan-03 20:40
sitebuilderMichael Dunn5-Jan-03 20:40 
GeneralRe: Problem with WTL Pin
User 98858-Jan-03 10:14
User 98858-Jan-03 10:14 
GeneralWTL: a newbie question Pin
Shah Shehpori5-Jan-03 18:41
sussShah Shehpori5-Jan-03 18:41 
GeneralRe: WTL: a newbie question Pin
Jörgen Sigvardsson17-Jan-03 12:29
Jörgen Sigvardsson17-Jan-03 12:29 
GeneralCRegKey QueryStringValue Pin
rbeckett5-Jan-03 17:01
rbeckett5-Jan-03 17:01 
GeneralRe: CRegKey QueryStringValue Pin
Michael Dunn5-Jan-03 17:24
sitebuilderMichael Dunn5-Jan-03 17:24 
GeneralGreat! Works Perfectly! Pin
rbeckett5-Jan-03 17:41
rbeckett5-Jan-03 17:41 
QuestionHow do I create Different view derived class ? Pin
Jose Cruz3-Jan-03 6:45
Jose Cruz3-Jan-03 6:45 
GeneralRegarding memory Pin
suresh_sathya1-Jan-03 20:14
suresh_sathya1-Jan-03 20:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.