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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:54:07+00:00 2026-06-15T14:54:07+00:00

I have some simple hypothetical static class in C++: #ifndef __STAT_H_ #define __STAT_H_ class

  • 0

I have some simple hypothetical static class in C++:

#ifndef __STAT_H_
#define __STAT_H_

class Stat {

 private:
  static vector<int> v;

 public:

  static void add_num(int num);
  static void clear_nums();
  static void get_count();
};

#endif

And the ccp file is so:

#include "Stat.h"

vector<int> v;


void Stat::add_num(int num) {
  v.push_back(num);
}

void Stat::clear_nums() {
  v.clear();
}

int Stat::get_num_count() {
  return v.size();
}

Now when I include in main.cpp file “Stat.h” and try to use some static method:

Stat::add_num(8);

the error during compilation is

undefined reference to ‘Stat::add_num(int)’

What can be the problem in this case? Thank you.

EDIT: sorry about addresses vector, it should be v there

  • 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-15T14:54:09+00:00Added an answer on June 15, 2026 at 2:54 pm

    It sounds like you have not included stat.cpp in compilation. So your linker cannot find an implementation for the static methods.

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

Sidebar

Related Questions

I have some simple code in a class: private ITemplate _content1 = null; [TemplateContainer(typeof(ContentContainer))]
I have some simple tables (multiple, all with class=parent) with multiple <tr> rows. The
I have some simple classes that looks like this: Class Favorites Guid UserId Guid
I have some simple constraints involving multiplication of reals in z3 that are producing
I have some simple JQuery / Javascript to perform some simple logic for all
I have some simple markup: <table> <tr> <td>Menu Item</td> </tr> </table> <div> <table> <tr>
i have some WinForms app (Framework to develop some simple apps), written in C#.
i have some WinForms app (Framework to develop some simple apps), written in C#.
CSS I have some simple CSS to apply a negative text-indent value on the
Let's say I have some simple Javascript like: <script> var hello = function(){ alert(Hello

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.