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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:50:48+00:00 2026-05-25T14:50:48+00:00

I have a file called Student.h which have the static integers in this way:

  • 0

I have a file called Student.h which have the static integers in this way:

    class Student
{
public:
    static int _avrA,_avrB,_avrC,_avrD;
};

and I have university.h that inherits Student.h .
On the implementation of University.cpp , one of the functions returns:

return (_grade_average*(Student::_avrA/Student::_avrB))+7;

and the compiler writes:

undefined reference to Student::_avrA.

Do you know why it happens?

  • 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-25T14:50:49+00:00Added an answer on May 25, 2026 at 2:50 pm

    You have declared those variables, but you haven’t defined them. So you’ve told the compiler “Somewhere I’m going to have a variable with this name, so when I use that name, don’t wig out about undefined variables until you’ve looked everywhere for its definition.”1

    In a .cpp file, add the definitions:

    int Student::_avrA; // _avrA is now 0*
    int Student::_avrB = 1; // _avrB is now 1
    int Student::_avrC = 0; // _avrC is now 0
    int Student::_avrD = 2; // _avrD is now 2
    

    Don’t do this in a .h file because if you include it twice in two different .cpp files, you’ll get multiple definition errors because the linker will see more than one file trying to create a variable named Student::_avrA, Student::_avbB, etc. and according to the One Definition to Rule Them All rule, that’s illegal.

    1 Much like a function prototype. In your code, it’s as if you have a function prototype but no body.

    * Because “Static integer members of classes are guaranteed to be initialised to zero in the absence of an explicit initialiser.” (TonyK)

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

Sidebar

Related Questions

I have a file called bbUI.js which contains this bit of JavaScript. Outside of
I have a file called entities.py, which contains the following code: class EntityClass: entities
i have file called data_out.xml which contains this xml code: <?xml version=1.0 ?> -
I have a file called function.php that has a function like this: public function
I have a file called hellowf.cs class MyFirstApp { static void Main() { System.Windows.Forms.MessageBox.Show(Hello,
I have a file called webpart.cs which is called by one of my masterpages
I have a file called 'removethese' who's contents looks like this: ./test_dir/file1 ./test_dir/file2 ./test_dir/file
I have a file called a.txt which I can open and read using fs.readFile.
I have a file called file.txt and it has this structure: owner_name : first_last_name
I have a file called inp.txt which lists 3 directory names #!/bin/sh while read

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.