DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2004
    Posts
    5

    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;
    }MY_STRUCT;

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


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

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

    structPtr_vector->push_back(thePtr);

    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.

    secondly,
    Danny Kalev

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

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

Bookmarks

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links