Trouble with classes

This is a discussion on Trouble with classes within the C++ Programming forums, part of the General Programming Boards category; Ok, so I have two classes. One of them is called WordQuizFile and the other is called WordQuiz. WordQuiz owns ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    126

    Question Trouble with classes

    Ok, so I have two classes. One of them is called WordQuizFile and the other is called WordQuiz. WordQuiz owns a WordQuizFile as a private member, like this:

    <code>
    class WordQuiz
    {
    private:

    WordQuizFile wqf;

    public:
    WordQuiz(char* wqfilename);
    //other irrelevant member functions
    ~WordQuiz();
    };
    </code>

    The problem is that the constructor for WordQuizFile has to take an argument(the name of the file). How can I do this??

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code tags are [CODE], not <CODE>

    You could have a Setup() method instead of using the constructor.
    I doubt it can be done in the class declaration like you usually do.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Here is one solution.

    WordQuiz::WordQuiz(char* wqfilename) : wqf(wqfilename)
    {}

    Kuphryn

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    126
    thanks guys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. having trouble using classes
    By rainman39393 in forum C++ Programming
    Replies: 2
    Last Post: 09-28-2008, 02:45 AM
  2. Trouble with private portion of Classes
    By SoBlue in forum C++ Programming
    Replies: 3
    Last Post: 01-22-2007, 04:32 PM
  3. Having trouble with Classes
    By flicka in forum C++ Programming
    Replies: 3
    Last Post: 10-08-2005, 08:41 AM
  4. Having Trouble Understanding Classes
    By prog-bman in forum C++ Programming
    Replies: 1
    Last Post: 05-19-2004, 12:44 PM
  5. Trouble Understanding Classes and Objects. Please Help.
    By Jeffcubed in forum C++ Programming
    Replies: 4
    Last Post: 12-06-2002, 01:23 PM

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