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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:51:49+00:00 2026-05-14T14:51:49+00:00

I am trying to do a simple hw problem involving namespace, static data members

  • 0

I am trying to do a simple hw problem involving namespace, static data members and functions. I am getting an unresolved external symbol error

Error   1   error LNK2001: unresolved external symbol "private: static double JWong::SavingsAccount::annualInterestRate" (?annualInterestRate@SavingsAccount@JWong@@0NA)    SavingsAccount.obj  SavingsAccount

And I don’t see why I am getting this error. Maybe I don’t know something about static variables compared to regular data members that is causing this error. Here is my code:

SavingsAccount.h file

#ifndef JWONG_SAVINGSACCOUNT_H
#define JWONG_SAVINGSACCOUNT_H

namespace JWong
{
    class SavingsAccount
    {
    public: 
        // default constructor
        SavingsAccount();
        // constructor
        SavingsAccount(double savingsBalance);

        double getSavingsBalance();
        void setSavingsBalance(double savingsBalance);
        double calculateMonthlyInterest();

        // static functions
        static void modifyInterestRate(double newInterestRate);
        static double getAnnualInterestRest();
    private:
        double savingsBalance;

        // static members
        static double annualInterestRate; 
    };
}

#endif

SavingsAccount.cpp file

#include <iostream>
#include "SavingsAccount.h"

// default constructor, set savingsBalance to 0
JWong::SavingsAccount::SavingsAccount() : savingsBalance(0)
{}

// constructor
JWong::SavingsAccount::SavingsAccount(double savingsBalance) : savingsBalance(savingsBalance)
{}

double JWong::SavingsAccount::getSavingsBalance()
{
    return savingsBalance;
}

void JWong::SavingsAccount::setSavingsBalance(double savingsBalance)
{
    this->savingsBalance = savingsBalance;
}

// returns monthly interest and sets savingsBalance to new amount
double JWong::SavingsAccount::calculateMonthlyInterest()
{
    double monthlyInterest = savingsBalance * SavingsAccount::annualInterestRate / 12; 
    setSavingsBalance(savingsBalance + monthlyInterest);
    return monthlyInterest; 
}

void JWong::SavingsAccount::modifyInterestRate(double newInterestRate)
{
    SavingsAccount::annualInterestRate = newInterestRate;
}

double JWong::SavingsAccount::getAnnualInterestRest()
{
    return SavingsAccount::annualInterestRate;
}
  • 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-14T14:51:49+00:00Added an answer on May 14, 2026 at 2:51 pm

    I’m presuming you are actually compiling the .cpp file (because the other functions link).

    The error is likely due to not defining the annualInterestRate static variable.

    You have declared it (in the class header), but it’s not defined. In your cpp file add:

    // static member definition
    double JWang::SavingsAccount::annualInterestRate = ...;
    

    See an article highlighting the difference between declaration and definition of static members.

    Section 9.4.2 of the C++ Standard says “The definition for a static data member shall appear in a namespace scope enclosing the member’s class definition.”

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

Sidebar

Related Questions

I am trying to figure out the following simple problem in order to get
I was trying to write a simple extension method for Color static class which
I'm trying to find a simple MySQL statement for the following two problems: I
I'm trying to make a simple blackjack program. Sadly, I'm having problems right off
I am trying something very simple, but for some reason it does not work.
I am trying to get simple jQuery to execute on my Content page with
I am trying to do simple tutorial in Visual Studio let someNumber = (2
I am trying to write simple Visual Studio Add-In for code generation. In my
I'm just trying to do simple scripting with F#, and Math.PI seems to have
I'm writing an application and I'm trying to tie simple AJAX functionality in. It

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.