Thread: problem

  1. #1
    Registered User
    Join Date
    Oct 2002


    actually the problem is when storing the data.
    when we try to retake the data , data is not found
    struct rooms
    int totrooms;
    int *roomnums;

    roomnums=new int(0);
    void getdata()
    cin>> totrooms;
    rs.roomnums=new int(rs.totrooms);
    for(int i=0;i<rs.totrooms;i++)
    file sr.write(.....);
    this code will work but only once

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    constructor for a struct called rooms called constructor?
    Are you trying to nest functions. This is not possible in c++. It can be approximated with functors but thats a different story.
    Maybe you should totally describe what you are trying to accomplish.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :-

  3. #3
    Registered User
    Join Date
    Aug 2002
    There are a few problems with your code. But I think the main problem is that you are trying to use new to arrayafy (if thats a word) your pointer. This does not work. When you new something into your pointer it does not turn it into an array if something is already being pointed to by that pointer. Instead it moves the pointer to the new address of the newly allocated space and the old space is lost and you have a memory leak.

    This line is your problem:
    rs.roomnums=new int(rs.totrooms);

    Instead you will have to use a linked list like CList.

    CList <int, int> rs.roomnum;
    rs.roomnum.AddTail(new int(rs.totrooms));

    Something like that.
    Best Regards,


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM