STL Vector and Custom Struct!

This is a discussion on STL Vector and Custom Struct! within the C++ Programming forums, part of the General Programming Boards category; I have this structure called hello with an integer inside it: Code: struct Hello{ int r; }; Im trying to ...

  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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21