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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:13:17+00:00 2026-05-27T11:13:17+00:00

I am working on a homework assignment, and I have almost everything done except

  • 0

I am working on a homework assignment, and I have almost everything done except for this obnoxious static value that our professor wishes us to use: value

The header file contains:

private:
    static int value;

And we have to have a function calculate the value, like so:

static void calculate()
{
    long a = 1L;
    int count = 0;

    while( a != 0 )
    {
        a = a << 1;
        count++;
    }

    value = count;
}

This is essentially calculating the number of bits in a long, using bit shifting.

However, I am getting the error ” undefined reference to `Class1::value’

I’ve spent the last hour and a half figuring this out, and it’s killing me. Any help would be great, all searches have come up dead.

Thanks!


Update:

I included

int Class1::value = 0;

However, now I am getting an error saying “error: int Class1::value is private

  • 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-27T11:13:18+00:00Added an answer on May 27, 2026 at 11:13 am

    In your *.cpp file add

    int ClassName::value = 0;
    

    This will allocate storage for a value.

    The piece of code that you actually have in a class declaration just declares this variable (makes the compiler aware that such a variable exists). However, each variable must be declared and defined. A definition will make sure the storage is put aside for this variable and create a symbol your compiler was unable to find before.

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

Sidebar

Related Questions

I have this school assignment that I've been working on and am totally stumped
I'm working on a homework assignment for CS1, and I almost have it finished
I'm working on a homework assignment (a project), for which one criterion is that
I'm working on this homework that's kind of confusing me... I am provided with
I'm working on a homework assignment to modify code given by my professor using
I am working on a homework assignment where I have to implement a MergeSort
I'm working on a homework assignment that asks me to create a calculator that
Some classmates and I are working on a homework assignment for Java that requires
I am working on my last homework assignment for COBOL this semester and I
I have a homework assignment and I've done the bare minimum of the assignment,

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.