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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:48:46+00:00 2026-05-27T09:48:46+00:00

I am trying to create an object of Player inside PlayerManager and I am

  • 0

I am trying to create an object of “Player” inside “PlayerManager” and I am getting the error in VS2010:

Error 1 error C2512: 'Player::Player' : no appropriate default constructor available c:\program files (x86)\microsoft visual studio 10.0\vc\include\memory 631 1 Server

Player.h:

#ifndef _PLAYER_H
#define _PLAYER_H

#include <iostream>
#include <string>

using namespace std;

class Player
{
public:
    Player(const string &name);
~Player(void);


private:
    string name_;
};

#endif

Here is the constructor in Player.cpp:

Player::Player(const string &name)
{

}

PlayerManager.h:

'#ifndef _PLAYERMANAGER_H
#define _PLAYERMANAGER_H

#include <string>
#include <vector>
#include <iostream>

#include "Player.h"

using namespace std;

class PlayerManager
{
public:
    PlayerManager(void);
    ~PlayerManager(void);

private:
    vector<Player> players;
};

#endif'

Here is where I create the object in PlayerManager.cpp:

PlayerManager::PlayerManager(void)
{
        Player test("Hello");
        players.resize(1000);
    for(int i=0; i < 960; i++){
        players.push_back(test);
    }
}

I don’t understand why it is ignoring the string “Hello”, I have tried creating a string object but gives same error.

I have also tried without adding the const & in the constructor but gives same error.

Any help would be appreciated, spend hours searching for an answer. Apologies if the layout is incorrect as this is my first time asking a question.

  • 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-27T09:48:47+00:00Added an answer on May 27, 2026 at 9:48 am

    The class std::vector requires that the class you use it with has a default constructor1. You’ll need to provide one for your class.

    If you really don’t want to provide one, you can give an instance of your class to vector in it’s constructor call, so that it will use that instance instead of trying to default-construct one:

    vector v(initialsize, Player("")); // or you can pass whatever string you want the default item to have
    

    If the vector that you are using to store Players is a member variable, you’ll need to pass it the default Player to use in the initialiser list:

    PlayerManager::PlayerManager() : players(initialsize, Player("")) { // assuming the vector is named players
        .... 
    }
    

    1 As R. Martinho Fernandes and Kerrek SB have pointed out in the comments, a default constructor is only required for this particular constructor of vector (the one that takes an initial size and when you don’t give it a default instance) and the member function resize when called with a single argument. If you use the constructor that takes iterators or a const Allocator&, or if you use resize with the second argument, then you don’t need a DC.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a new object of type T via its constructor when
I'm trying to create a Database object for myself in .net. The constructor takes
I'm trying to create a boundary for a player object, controlled with arrow keys,
Trying to create COM -object on server. code is: var myGuid = new Guid(530A1815-820C-11D3-BBB7-008048DE406A);
I am trying to create an object of Console class, but could not succeed.
I'm trying to create an object file which can be useable in any computer.
How can I do inheritance with this example. I'm trying to create an object
I am trying to create a UserDon object, and trying to generate the get
I'm trying to create a custom object that behaves properly in set operations. I've
I am trying to create a date object that is 90 days from a

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.