473,507 Members | 3,112 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

STL inside a structure (I'm stuck!)

4 New Member
I'm REALLY stuck on this:

Expand|Select|Wrap|Line Numbers
  1. // data
  2. typedef struct {
  3.   int foo;
  4.   list<int> mylist;
  5. } MyStructRec, *MyStruct; // MyStruct it's a pointer
  6.  
  7. // code
  8. MyStruct struct = (MyStruct) malloc(sizeof(MyStructRec));
  9.  
  10. struct->mylist.push_back(123); // mylist is not initialized!!!
  11.  
...How do I initialize (allocate) the STL list???
Do I have to mess with allocators?
Really, no clue.
Thanks!
Jun 7 '07 #1
3 1414
AdrianH
1,251 Recognized Expert Top Contributor
I'm REALLY stuck on this:

Expand|Select|Wrap|Line Numbers
  1. // data
  2. typedef struct {
  3.   int foo;
  4.   list<int> mylist;
  5. } MyStructRec, *MyStruct; // MyStruct it's a pointer
  6.  
  7. // code
  8. MyStruct struct = (MyStruct) malloc(sizeof(MyStructRec));
  9.  
  10. struct->mylist.push_back(123); // mylist is not initialized!!!
  11.  
...How do I initialize (allocate) the STL list???
Do I have to mess with allocators?
Really, no clue.
Thanks!
Try not using malloc. Use new.

Expand|Select|Wrap|Line Numbers
  1. // code
  2. MyStruct struct = new MyStructRec();
  3.  
Also, your use of typedef is one I've only seen M$ do. I'd get out of that habbit. Or atleast use the naming convention that M$ does. It is confusing.


Adrian
Jun 7 '07 #2
Sga
4 New Member
Try not using malloc. Use new.
Thanks A LOT!
I also understood that I had some holes in my new/delete knowledge.
...Now I'm up to some code cleaning...

Also, your use of typedef is one I've only seen M$ do. I'd get out of that habbit.
It is an old habit... But Linux seems to cope well with it, so...
Cheers!
Jun 8 '07 #3
AdrianH
1,251 Recognized Expert Top Contributor
Thanks A LOT!
I also understood that I had some holes in my new/delete knowledge.
...Now I'm up to some code cleaning...



It is an old habit... But Linux seems to cope well with it, so...
Cheers!
Good luck.


Adrian
Jun 8 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1305
by: [Mystic] | last post by:
Hi (again). I've created a page class for dynamicly making pages. It works fine apart from one problem im having. I'm making it include the main body of the page from an html file. So:...
2
3736
by: Oli | last post by:
Hi Here is the problem section of code..... <% else intOrderID = cstr(Session("OrderID")) set rsProd = Server.CreateObject("ADODB.Recordset")
0
1063
by: Zoran Stipanicev | last post by:
Hi! I've declared structure in function and inside it template structure.It was all great untile i presed build. I'm using vc++ .net 2003 the error was something like: You can't declare template...
3
1589
by: james545 | last post by:
I saw some code written where member functions were written inside struct definition blocks and was wondering if this is an advisable or common style of programming in C/C++? The type of code I...
22
3735
by: Mike Krous | last post by:
Hello All, I am having some problems modeling a relationship properly and could use some advice. My final question is at the bottom of this post (everything else is explanation). Basically what I...
1
6406
by: Mikko Penkkimäki | last post by:
I have a struct in C#-project and C++-project. I use the struct in C# but it has to be filled in C++. I know that arrays work like this: In C++ code: struct teststruct { char str; float...
0
1164
by: SM | last post by:
Hello, I have a xml file that contains the CD library of one artist. I want to extract all the tracks from a specific CD. I was able to extract the title of all the cd's but not the tracks of one...
1
1012
by: craigsoad | last post by:
im new to the vb coding does anyone know how to link forms cause im stuck
0
1264
by: pavankumar106 | last post by:
Hi im stuck in sm simple pb ..im having a datalist in wich im having images and each image have a delete button below it.now wen I press delete button I shud be able to delete that image in dataset...
13
1752
by: canabatz | last post by:
i got for example this result from data base: user1 user1 user1 user2 user2 user1 user1
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.