-
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
-
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
-
My Bad, I figured it out. Sometimes I wonder what goes on inside my head...
vanderpj123
Similar Threads
-
Replies: 4
Last Post: 04-14-2006, 09:09 AM
-
By Marcos in forum VB Classic
Replies: 3
Last Post: 01-25-2006, 11:18 AM
-
By Scott in forum VB Classic
Replies: 12
Last Post: 12-21-2001, 04:21 PM
-
Replies: 1
Last Post: 11-27-2001, 06:53 AM
-
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
Forum Rules
|
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
|
Bookmarks