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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:11:21+00:00 2026-06-14T23:11:21+00:00

I have this a class called ‘Card’ and I am trying to store some

  • 0

I have this a class called ‘Card’ and I am trying to store some of its objects in a std::map
Card.hpp:

class Card
{
public:
    enum ValueType { NOVALUE, ACE };
    enum FaceType { NOFACE, CLUBS };

    Card(const ValueType & _value, const FaceType & _face);
    Card(const Card & _card);
private:
    ValueType m_value;
    FaceType m_face;
};

Here is how I store and access it:
Deck.hpp:

#include <map>

class Card;

class Deck
{
    public:
        Deck();

        std::size_t length() const;

        Card get_card(const int & _num);

    private:
        std::map<int, Card> m_deck;
};

Deck.cpp:

#include "Card.hpp"

Deck::Deck()
{
    m_deck.insert(std::pair<int, Card>(0, Card(Card::NOVALUE, Card::NOFACE)));
    m_deck.insert(std::pair<int, Card>(1, Card(Card::ACE, Card::CLUBS)));
}
std::size_t Deck::length() const
{
    return m_deck.size();
}

Card Deck::get_card(const int & _num)
{
    return m_deck[_num];
}

Now, when I compile it I get following error:

/usr/include/c++/4.6/bits/stl_map.h:453:45: error: no matching constructor for initialization of 'mapped_type' (aka 'Card')
          __i = insert(__i, value_type(__k, mapped_type()));
                                            ^
Deck.cpp:69:18: note: in instantiation of member function 'std::map<int, Card, std::less<int>, std::allocator<std::pair<const int, Card> > >::operator[]' requested here
    return m_deck[_num];
                 ^
./Card.hpp:30:2: note: candidate constructor not viable: requires 2 arguments, but 0 were provided
        Card(const ValueType & _value, const FaceType & _face);
        ^
./Card.hpp:32:2: note: candidate constructor not viable: requires 1 argument, but 0 were provided
        Card(const Card & _card);
        ^
1 error generated.

Why am I getting this error? I am using Card only as a value!

  • 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-14T23:11:23+00:00Added an answer on June 14, 2026 at 11:11 pm

    The problem is that for a map, m_deck[_num] is designed to insert a default constructed Card if the element isn’t already there. And Card doesn’t have a default constructor.

    You can use map::find to see if the entry is there, without creating one.

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

Sidebar

Related Questions

I'm trying to validate an ID. I have this class called ManejadorTickets in which
I have this small class called City that simply holds some information about a
I have a class called 'subscribedQueue'. This class receives its data via its subscribed
i have this class called MemoryManager, it is supposed to implement a simple smart
I have this class called SiteAsyncDownload.cs Here's the code: public class SiteAsyncDownloader { WebClient
I have this class called PollFrame that extends JFrame in a file called PollFrame.java
I have a class called MyClass This class inherits IEquatable and implements equals the
Let's say I have a model class called Project, but instead of this: class
I have this in my class When the second function is called php errors
I have an enum class called Gender , and I have values in this

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.