problem

This is a discussion on problem within the C++ Programming forums, part of the General Programming Boards category; actually the problem is when storing the data. when we try to retake the data , data is not found ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    17

    problem

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

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

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    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 :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    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,

    Bonkey

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, 05: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, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21