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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:20:40+00:00 2026-06-09T17:20:40+00:00

After reading up on class tutorials on the C++ site, I have learned the

  • 0

After reading up on class tutorials on the C++ site, I have learned the following piece of code which I then tried to work with:

class CVector {
  public:
    int x,y;
    CVector () {};
    CVector (int,int);
    CVector operator + (CVector);
};

CVector::CVector (int a, int b) {
  x = a;
  y = b;
}

After which I wrote the following code, in order to learn to program C++ classes efficiently and to write cleaner code:

class Player {
public:
    string name;
    int level;
};

Player::Player(int y) {
    level = y;
}

However it gives me error C2511: ‘Player::Player(int)’ : overloaded member function not found in ‘Player’.
I have searched for the error but I did not find how to fix it. What’s wrong with this code?

  • 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-09T17:20:41+00:00Added an answer on June 9, 2026 at 5:20 pm

    You need to declare the single parameter construction:

    class Player {
    public:
        Player(int y);
        std::string name;
        int level;
    };
    

    Once you do this, there will no longer be a compiler synthesized default constructor, so if you need one, you would have to write your own. Also consider making the single parameter constructor explicit if you do not want implicit conversions from int.

    class Player {
    public:
        explicit Player(int y); // no implicit conversions from int
        Player() :name(), int() {} // default constructor and implementation
        std::string name;
        int level;
    };
    

    Also, prefer the constructor initialization list to assigning values in the constructor body, if possible. There are plenty of SO questions on that topic so I won’t elaborate here. This is how you would do it:

    Player::Player(int y) : level(y) {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After reading the android documentation about String, which includes this: This class is implemented
I have the .java, .class, .cpp, .h files: http://www.ibm.com/developerworks/java/tutorials/j-jni/section2.html After reading TotalFrickinRockstarFromMars's comment, I
I'm new with Java NIO, after reading some tutorials, I've tried my own to
I have gone through the following tutorial : http://www.javaworld.com/community/node/2915 And after reading the above
After reading monkeytalk faq from http://www.gorillalogic.com/testing-tools/monkeytalk/documentation/monkeytalk-faq : How does it all work? MonkeyTalk is
After reading the Service Oriented Architecture Principles site and the respective Wikipedia article I
I need to change status line message from a handler class. After reading the
Recently, after reading a lot of tutorials around the Internet, I've noticed that some
I'm reading Ruby on Rails tutorial. On chapter 9 after wrote all the code,
After reading some tutorials I am still unclear on some points about memory management

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.