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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:34:17+00:00 2026-06-15T09:34:17+00:00

Possible Duplicate: Resolving a linker error: undefined reference to static class members This declaration:

  • 0

Possible Duplicate:
Resolving a linker error: undefined reference to static class members

This declaration: static unsigned NbCPassant; only works when it’s outside the class. If I put it inside, (to have it private) this doesn’t compile, with the error:

undefined reference to `(anonymous namespace)::CPassant::NbCPassant'

I don’t get why. Here’s the code:

#include <iostream>
#include <unistd.h>
#include <vector>
#include "SleepChronogram.h"
#include "nsUtil.h"

using namespace std;
using namespace boost;
using namespace boost::posix_time;
using namespace nsUtil;

static unsigned CptThreads;

char * nsUtil::clrscr = "\033[2J";    //    Clear screen

#define GOTOXY nsUtil::gotoxy

GOTOXY::gotoxy (int x, int y) : m_x (x), m_y (y) {}

ostream & nsUtil::operator << (ostream & os, const gotoxy & m)
{
    return os << "\033[" << m.m_y << ';' << m.m_x << 'H';
}

#undef GOTOXY

namespace
{
    void RendezVous ()
    {
        CptThreads--;
        while(CptThreads)
        {
            condition_variable Cond;
            mutex mut;
            unique_lock<boost::mutex> lock(mut);
            Cond.wait(lock);
        }
    }


    class CPassant {
    private:
        static unsigned NbCPassant;

        unsigned NbP;
        unsigned TpsAvantRDV;
        unsigned TpsApresRDV;

    public:

        CPassant (unsigned TpsAv, unsigned TpsAp)
        :NbP(NbCPassant++) , TpsAvantRDV (TpsAv), TpsApresRDV (TpsAp) {}

        void operator () ()
        {
            sleep(TpsAvantRDV);
            RendezVous();
            sleep(TpsApresRDV);
        }

    };
}

void nsUtil::SleepChronogram (unsigned Num, 
                              unsigned & Col,
                              char Status, 
                              unsigned Duree,
                              boost::mutex & ioMutex,
                              unsigned Decal   /* = 10u */,
                              unsigned Periode /* = 1u  */)
    throw (std::ios_base::failure)
{
    for (unsigned i = Duree; i--; )
    {
        {
            lock_guard <mutex> Lock (ioMutex);
            cout << gotoxy (Col++, Num + Decal) << Status << flush;
        }
        this_thread::sleep (seconds (Periode));
    }

} // SleepChronogr()

int main (int argc, char ** argv)
{
    if (argc != 1)
        return 0;
    int NbThreads = atoi(argv[1]);
    if (NbThreads <1)
        return 0;

    vector <CPassant> VCPassant;
    VCPassant.reserve(NbThreads);
    for (int DelaiAv, DelaiAp, i (0) ; i < NbThreads; ++i)
    {
        cin >> DelaiAv >> DelaiAp;
        VCPassant.push_back(CPassant(DelaiAv, DelaiAp));
    }
    return 0;
}
  • 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-15T09:34:18+00:00Added an answer on June 15, 2026 at 9:34 am

    You are only declaring NbCPassant in your code, you need to define it as well:

    class CPassant { 
    private:
        // Declare the variable
        static unsigned NbCPassant;
        ...
    };
    
    // Define the variable
    unsigned CPassant::NbCPassant;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Including FSharp.Core in a C# project: resolving type collisions I have referenced
Possible Duplicate: Difference between class property mVar and instance variable self.mVar I am new
Possible Duplicate: Form that removes WWW. and prints result on input? I'm using this
Possible Duplicate: JavaScript URL encode some scripts working fine started to give me this
Possible Duplicate: $(this) doesn't work in a function I'm writing post removing code in
Possible Duplicate: Accessing inherited variable from templated parent class I have been implementing a
Possible Duplicate: Why doesn't the weakref work on this bound method? I'm using weakrefs
Possible Duplicates: Finding duplicate files and removing them. In Python, is there a concise

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.