Thread: Problems with project

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    3

    Question Problems with project

    I'm working on this program(project) that parses some kind of messages and came up against two problems.
    The first one is how to read data from .vmg file. Every .vmg file keeps data for one object of class Message. So do I first need to encode vmg file to txt and than read data from created txt file?
    The second problem is how to create object of class Array, which elements are objects of class Message.
    Something like this:
    Code:
    class Array {
    Message** el; //class Message
    public:
    //...
    }
    So basically how to create an array of pointers to objects(but the size of an array is unknown)?Any suggestions?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by ghost_rider View Post
    So basically how to create an array of pointers to objects(but the size of an array is unknown)?Any suggestions?
    std::vector<Message*>

    Why do you need pointers anyway?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    3
    I forgot to mention that I can't use std::vector or linked lists, for the same reason I need pointers. This is a school project and they were clear about these conditions. It sucks, but that's the way it is.
    Last edited by ghost_rider; 11-05-2011 at 03:52 AM.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Right. Then you need a pointer. You need a pointer because you must dynamically allocate the number of elements in your array (which contains pointers).
    Don't forget that you must call delete [] also.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    3
    But how do I initialize object of class Array? I have to put like 1000 objects of class Message into one object of class Array. And also I don't know the number of objects of class Message. It could be 1000 or 10,000.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    When you purchase a hard drive, do you know beforehand exactly how much space you need in all the coming years?
    What happens when your hard drive fills up? What do you do then (without deleting stuff)?
    What does this have to do with the problem at hand? I think that if you think about it a while, it will make sense. It's all about logic.

    To create an Array object, you can do either:

    Array obj;

    or

    Array* myobj = new Array;
    //...
    delete myobj;

    And if you need N new Arrays, you can do

    Array* myobj = new Array[N];
    //...
    delete [] myobj;
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems With My Project
    By pat3lbr0s2014 in forum C++ Programming
    Replies: 2
    Last Post: 01-09-2010, 06:13 PM
  2. First "big" project and having problems...
    By rabbit in forum C++ Programming
    Replies: 1
    Last Post: 02-11-2006, 09:34 PM
  3. problems in with design of a server project.
    By codec in forum C++ Programming
    Replies: 4
    Last Post: 02-28-2003, 09:11 AM
  4. DJGPP project problems
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 06-08-2002, 07:16 PM
  5. your 11th & 12th grade c++ project or similar project
    By sleepyheadtony in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 01-13-2002, 05:14 PM