DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2004

    Passing Vector to another function for modification

    What I am attempting to do, is basically load a vector from another function. The code below is what I have attempted, but it won't work. In short, I declare a vector that will contain pointers to a struct. I pass the address of the vector to another function that will create a number of structs using malloc and store the pointers to those memory locations in the Vector. It doesn't seem to be working, can anyone help????

    typedef my_struct* struct_ptr;
    typedef struct my_struct{
    double value;

    void loadvector(vector<struct_ptr>* structPtr_vector){
    for(int j = 0; j < 10; j++){
    struct_ptr thePtr = (struct_ptr)malloc(sizeof(MY_STRUCT));

    void function_1(){
    vector<struct_ptr> structPtr_vector;
    printfVector(structPtr_vector); //code not here I got this...

  2. #2
    Join Date
    Nov 2003
    Fosr starters, you need to call push_back like this:


    Secondly, what are the prototypes of
    function_2 & printfVector?
    what are the error messages you're getting, if any?
    Finally, malloc doesn't create a real object. It just returns a chunk of raw memory so you can't expect the loadVector function to fill the vector with meaningful data.

    Danny Kalev

  3. #3
    Join Date
    Aug 2004
    My Bad, I figured it out. Sometimes I wonder what goes on inside my head...

Similar Threads

  1. Getting a GUI to run
    By Eric in forum Java
    Replies: 4
    Last Post: 04-14-2006, 09:09 AM
  2. Packed Data(Comp-3, etc)
    By Marcos in forum VB Classic
    Replies: 3
    Last Post: 01-25-2006, 11:18 AM
  3. Getting a list of files into an array
    By Scott in forum VB Classic
    Replies: 12
    Last Post: 12-21-2001, 04:21 PM
  4. Getting a GUI to function
    By Eric in forum Java
    Replies: 1
    Last Post: 11-27-2001, 06:53 AM
  5. Trying to print a PDF File from VB
    By Kunal Sharma in forum VB Classic
    Replies: 2
    Last Post: 04-25-2000, 03:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.