Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3353600
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:10:15+00:00 2026-05-18T02:10:15+00:00

I am looking to be pointed in the right direction. I have 1 class

  • 0

I am looking to be pointed in the right direction.
I have 1 class Event

class Event{
private:
 vector<string> Question;
 char Mode;// 1 = Ascending 2 = Descending 3 = None
 string EventName;
public:
    Event(string Name){
        EventName = Name;
        SetQuestionSize();
        SetQuestion();
        Mode = 3; 
    }

    void SetName(string NewName){
        EventName = NewName;
    }
    void SetQuestionSize(){
        Question.resize(15);
    }

    int ReturnQuestionSize(){
        return Question.size();
    }

    void SetQuestion(){
        Question[0]="Enter ";
        Question[1]="1 ";
        Question[2]="to ";
        Question[3]="sort ";
        Question[4]="in ";
        Question[5]="ascending ";
        Question[6]="order, ";
        Question[7]="2 ";
        Question[8]="for ";
        Question[9]="Descending, ";
        Question[10]="or ";
        Question[11]="3 ";
        Question[12]="to ";
        Question[13]="ignore ";
        Question[14]=EventName;
    }

    string ReturnQuestion(int Index){
        return Question[Index];
    }

    /*vector<string> ReturnQuestion(){
 return Question;
    }*/

    void SetMode(char NewMode){
 if (NewMode == '0' || NewMode == '1' || NewMode == '2')
 Mode = NewMode;
}

    char ReturnMode(){
 return Mode;
    }

    string ReturnName(){
        return EventName;
    }
};

This is will be a member of a second object, which will use Event’s functions to store data in Event’s members.

The problem I’m having is declaring an array of Event objects in my second object. When researching I came across ways to use an array of pointers to the first object, and some operator ‘->’ that I’m guessing is related to virtual functions.

class WhatTheyWant{
    Event *events[2];
public:
    WhatTheyWant(){
        events[0]= new Event("Miss");
        events[1]= new Event("Dodge");
    }
};

I’m very ignorant about pointers, and I know I will have to learn them eventually, but are they the best way to go or is there a better.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:10:16+00:00Added an answer on May 18, 2026 at 2:10 am

    Since your Event class doesn’t have a default constructor, you need to explicitly construct each object with its name, so the way you’re doing it currently is the only way to do it.

    If you add a default constructor to Event, you can do it in at least two other ways:

    If you will always have a (small) fixed number of objects, you can just declare an array of constant size:

    Event events[2];
    

    Doing this will automatically construct the objects when WhatTheyWant is created, so you just need to set the names afterwards:

    WhatTheyWant() {
      events[0].SetName("Miss");
      events[1].SetName("Dodge");
    }
    

    If you want to have a variable number of events, you can declare a single pointer and dynamically allocate an array of objects:

    Event *events;
    

    And you could probably give the number as a parameter to the constructor:

    WhatTheyWant(int numEvents) {
      events = new Event[numEvents];
      for (int i = 0; i < numEvents; i++)
        events[i]->SetName("...");
    }
    

    Also, not directly related to your question, but your Mode variable would be better modeled using an enumeration instead of a char. Using an enum makes it clearer as to what the variable really means, rather than using values like 0, 1 and 2. For example:

    public:
      enum ModeType { Ascending, Descending, None };
    private:
      ModeType Mode;
    public:
      Event() {
        ...
        Mode = Ascending;
      }
      void SetMode(ModeType NewMode) {
        Mode = NewMode;
      }
      ModeType ReturnMode() {
        return Mode;
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just looking to be pointed in the right direction: Have standard input to a
Looking to be pointed in the right direction to create the ie. someone emails
Looking for a method or to be pointed in the right direction so I
Im looking to be pointed in the right direction. My site that i'm testign
i need a pointer i the right direction. I have been looking around and
I am looking for a pointer in the right direction, rather than a full
I'm looking for a pointer in the right direction to get started with writing
So, I'm looking through a java library (JScience) after someone here thoughfully pointed me
I'm looking for the right way to allocate and deallocate chars arrays of dynamic
I am looking to have one of my Windows Forms applications be run programmatically—from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.