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 8875877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:05:39+00:00 2026-06-14T19:05:39+00:00

i want to run the function Run in the main, but am not allowed

  • 0

i want to run the function Run in the main, but am not allowed to create object due to no default constructor. when i try to create the default constructor, i receive the message, ‘Error”Game::Game int maxComponents)” provides no initialiser for:’

//Game.h 
#pragma once
#include "GameComponent.h"
#include <time.h>
class Game
{
private:
    int componentCount;
    GameComponent** components;
    const int TICKS_1000MS;
public:

    Game(){}    //this does not work either
    Game(int maxComponents){}   //this does not work as my default constructor
    ~Game();
    void Add(GameComponent*);
    void Run();

};

//Game.cpp
#pragma once
#include "StdAfx.h"
#include "Game.h"
#include <iostream>
#include<time.h>
using namespace std;


void Game::Add(GameComponent*)
{
    components= new GameComponent*[componentCount];


}
void Game::Run()
{

    time_t rawtime;
    struct tm * timeinfo;

    time ( &rawtime );
    timeinfo = localtime ( &rawtime );      
    //cout << timeinfo->tm_hour<< ":" << timeinfo->tm_min << ":" << timeinfo->tm_sec << endl;

    for(int n=0;n<componentCount;n++)
    {
        components[n]->Update(timeinfo);

    }
}


Game::~Game()
{
}


//main.cpp
#include "stdafx.h"
#include <iostream>
#include "Game.h"
#include <time.h>

using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    Game obj1;
    obj1.Run();
    system("pause");
    return 0;
}

So, how do i create a default constructor here? i’ve tried to use member initialising too, doesn’t work. and copy constructor.

  • 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-06-14T19:05:40+00:00Added an answer on June 14, 2026 at 7:05 pm

    A default constructor is a constructor that takes no arguments. So, you should declare a constructor that looks something like this:

    Game() { }
    

    You can keep your other constructor – normal function overloading applies to constructors, so it will use your Game(int) constructor when you specify a single integer argument, and Game() when you specify no arguments.

    However, in your case Game contains a const int member (TICKS_1000MS). Since it’s const, it’s expected to be initialized in the constructor. So you should do something like this:

    Game() : TICKS_1000MS(123) { } // replace 123 with whatever the value should be
    

    You need to do that for all constructors.

    It’s a little silly to have a non-static const member of a class which is always initialized to the same value (as opposed to a value passed in as an argument to the constructor). Consider making it an enum instead:

    enum { TICKS_1000MS = 123 };
    

    or, a static const member:

    static const int TICKS_1000MS;
    

    and initialize it in Game.cpp:

    const int Game::TICKS_1000MS = 123;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to run function inside web service (.asmx file) $.ajax({ type: POST, contentType:
Want to run javascript function from parent window in child window Example I have
I want to run a function when a checkbox is checked or unchecked. However,
I want to run a function in TruClient (Firefox) every 0.1 seconds using window.setTimeout:
I want to run a function (to render flash messages) after a backbone.navigate call.
I have a C# application, and I want to run a function which is
I want to run this PHP function -- $querystring_arr='maxResults=50&startIndex=50&sort=date'; $str=preg_replace((&startIndex=)?[0-9]*(&)?,&startIndex=.$sindex.&,$querystring_arr); When I print $str
Let's say I want to run the same function on every one of my
I want to run a simple JavaScript function on a click without any redirection.
I have a function that I want to run when a specific URL path

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.