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

  • Home
  • SEARCH
  • 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 3456004
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:41:01+00:00 2026-05-18T09:41:01+00:00

I am currently implementing a Deck class that represents a 52 card playing deck.

  • 0

I am currently implementing a Deck class that represents a 52 card playing deck. It uses the boost Random library to shuffle integers that represent cards.

#include <iostream>
#include <fstream>
#include "constants.hpp"
#include <boost/program_options.hpp>

#include <vector>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/variate_generator.hpp>

boost::mt19937 gen(std::time(0));

class Deck{
    private:
        std::vector<int> cards;
        int cardpointer;
        static ptrdiff_t choosecard(ptrdiff_t i);
        ptrdiff_t (*pchoosecard)(ptrdiff_t);
    public:
        Deck();
        void shuffle();
        int pop();
};

Deck::Deck(){
    for(int i=1; i<=52; i++){
        cards.push_back(i);
    }
    cardpointer = -1;
    pchoosecard = &choosecard;
}

ptrdiff_t Deck::choosecard(ptrdiff_t i){
    boost::uniform_int<> dist(0,i);
    boost::variate_generator< boost::mt19937&, boost::uniform_int<> > cardchoice(gen, dist);
    return cardchoice();
}

void Deck::shuffle(){
    std::random_shuffle(cards.begin(), cards.end(), pchoosecard);
}

I want to move the “boost::mt19937 gen(std::time(0));” line to be part of the class, however I’m having problems doing so, since I get this error when I move it into the class definition:

$ make
g++ -I /usr/local/boost_1_45_0/ -c main.cpp
main.cpp:22: error: ‘std::time’ is not a type
main.cpp:22: error: expected ‘)’ before numeric constant
main.cpp:22: error: expected ‘)’ before numeric constant
main.cpp:22: error: expected ‘;’ before numeric constant
main.cpp: In static member function ‘static ptrdiff_t Deck::choosecard(ptrdiff_t)’:
main.cpp:39: error: ‘gen’ was not declared in this scope
make: *** [main.o] Error 1
  • 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-18T09:41:01+00:00Added an answer on May 18, 2026 at 9:41 am

    If you’re making it a normal class variable, initialize it in the constructor:

    class Deck {
        ...
        public:
            boost::mt19937 gen;
    };
    
    Deck::Deck() : gen(std::time(0))
    {
        ...
    }
    

    If you’re making it static (it looks like you are, since you’re using gen from choosecard, which is static), you still need a declaration outside the class:

    class Deck {
        ...
        public:
            static boost::mt19937 gen;
    };
    
    boost::mt19937 Deck::gen(std::time(0));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently implementing a raytracer. Since raytracing is extremely computation heavy and since I
I've been looking at the DropBox Mac client and I'm currently researching implementing a
I am currently having a hardtime understanding and implementing events in C# using delagates.
I'm currently in the process of implementing a number of different assignment algorithms for
I'm implementing a document server. Currently, if two users open the same document, then
I'm currently working on a Google Maps project and am implementing a search function.
I'm currently writing an ASP.Net app from the UI down. I'm implementing an MVP
What would the differences be in implementing remote business logic? Currently we are planning
Implementing Equals() for reference types is harder than it seems. My current canonical implementation
Currently, I don't really have a good method of debugging JavaScript in Internet Explorer and

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.