Thread: Instantiating objects when you don't know the constructor arguments?

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    4

    Instantiating objects when you don't know the constructor arguments?

    Hello all,

    I'm trying to complete a homework exercise for college, but I'm stuck on one point. The assignment is to write a program that marshals and unmarshals several Student objects. The marshaling is done by the StudentMarshalling class.

    The problem I'm having is this: The Student object *requires* the name and score array of the student to be passed in when the student is created. So we can't use a for loop to assign values to the Student data. Nor can we do this:

    Student* foo = new Student[10];

    As such I'm trying to figure out how my StudentMarshall.unmarshal method can return to my main.cpp file an array of Student objects.

    Can anyone assist me on this (and my apologies for any lack of clarity in my explanation!)

  2. #2
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    rewrite the student class to include a more generic constructor
    hello, internet!

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    4
    Originally posted by moi
    rewrite the student class to include a more generic constructor
    I would love to, but the assignment dictates we cannot rewrite any part of the class.

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Can I see that student class? You could use vectors.

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    272
    As such I'm trying to figure out how my StudentMarshall.unmarshal method can return to my main.cpp file an array of Student objects.
    Can it return an array of pointers?
    Joe

  6. #6
    Registered User
    Join Date
    Dec 2002
    Posts
    4

    Talking Problem Solved

    Rather than create a pointer to an array of objects whose constructor arguements I didn't know, I just created an array of pointers.

    Thanks to everyone who offered me help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. most efficient way to write filestream objects?
    By darsunt in forum C++ Programming
    Replies: 3
    Last Post: 01-26-2009, 05:17 PM
  2. Replies: 60
    Last Post: 12-20-2005, 11:36 PM
  3. Question about cout an stack object?
    By joenching in forum C++ Programming
    Replies: 8
    Last Post: 05-08-2005, 10:10 PM
  4. chain of objects within pop framework help needed
    By Davey in forum C++ Programming
    Replies: 0
    Last Post: 04-15-2004, 10:01 AM
  5. array of objects?
    By *~*~*~* in forum C++ Programming
    Replies: 4
    Last Post: 05-31-2003, 05:57 PM