Thread: STL Vector and Custom Struct!

  1. #1
    Unregistered
    Guest

    STL Vector and Custom Struct!

    I have this structure called hello with an integer inside it:
    Code:
    struct Hello{
    int r;
    };
    Im trying to resize the Hello struct so I can have Hello[0] Hello[1] etc etc with the vector template, but im having a problem. You see, the Hello.reserve() function for the structure, isnt working (capacity returns always 0), cause it takes as data type a Hello structure and not a integer. The same thing goes for the push_back. Im stuck here, can someone help?

  2. #2
    Unregistered
    Guest
    Can someone help me please??

  3. #3
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Perhaps you need to post some code; the description of your problem is as clear as mud. Have you implemented your own resevre and capacity functions for Hello? Or are you refering to the std::vector methods? Do you mean something like -

    Code:
    #include <iostream>
    #include <vector>
    
    using namespace std;
    
    struct Hello{
    int r;
    };
    
    
    int main()
    {
    	vector <Hello> h;
    	h.reserve(10);
    	cout << h.capacity();
    
    	return 0;
    }
    ?

  4. #4
    Unregistered
    Guest
    Its fine, I found it. Thanks.

Popular pages Recent additions subscribe to a feed