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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:59:47+00:00 2026-05-26T22:59:47+00:00

my program is simple. a class of a bank account. Each account has a

  • 0

my program is simple. a class of a bank account. Each account has a balance and an ower. each account has the same interest rate. I got the error when compile it. What’s wrong? Thanks in advance.

  2 #include <iostream>
  3 #include <string>
  4 using namespace std;
  5 class bank
  6 {
  7 private:
  8         double balance;
  9         string owner;
 10         static double InterestRate;
 11 public:
 12         static void AccountInfo(const bank& ac)
 13         {
 14                 cout << "name: " << ac.owner << endl << "balance: " << ac.balance;
 15         }
 16         static void SetAccount(bank& ac)
 17         {
 18                 cout << "enter a name: " << flush;
 19                 cin >> ac.owner;
 20                 cout << "enter a balance: " << flush;
 21                 cin >> ac.balance;
 22         }
 23         static void SetRate(const double& n)
 24         {
 25                 InterestRate = n;
 26         }
 27         static void Balance(bank& ac)
 28         {
 29                 ac.balance += ac.balance * InterestRate;
 30         }
 31 };
 32 int main ()
 33 {
 34         bank NewAccount;
 35         bank::SetAccount(NewAccount);
 36         bank::SetRate(0.15);
 37         bank::Balance(NewAccount);
 38         bank::AccountInfo(NewAccount);
 39 return 0;
 40 }

and the output is:

  /tmp/ccUh8Sd9.o: In function `bank::SetRate(double const&)':
    e1237.cpp:(.text._ZN4bank7SetRateERKd[bank::SetRate(double const&)]+0x12): undefined reference to `bank::InterestRate'
    /tmp/ccUh8Sd9.o: In function `bank::Balance(bank&)':
    e1237.cpp:(.text._ZN4bank7BalanceERS_[bank::Balance(bank&)]+0x1c): undefined reference to `bank::InterestRate'
    collect2: ld returned 1 exit status
  • 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-26T22:59:47+00:00Added an answer on May 26, 2026 at 10:59 pm

    You just declared the static member InterestRate in your class definition but,
    You also need to define your static member in one of your cpp file:

    double bank::InterestRate = 0.0;
    

    Without this the linker cannot find its definition and gives the linking error.

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

Sidebar

Related Questions

I'm making a simple program in Objective-C. It has one class with a lot
I am compiling a simple program class Test { public static void main(String[] args)
Given the following simple program: import wx class TestDraw(wx.Panel): def __init__(self,parent=None,id=-1): wx.Panel.__init__(self,parent,id,style=wx.TAB_TRAVERSAL) self.SetBackgroundColour(#FFFFFF) self.Bind(wx.EVT_PAINT,self.onPaint)
This is my simple program in Java: public class Counter extends Thread { public
I'm writing a simple program. There is only one class in it. There is
I created a simple WCF demo: Server Side: namespace ServerSide { class Program {
I have this simple example: using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program
The following simple program in Java uses the java.util.Random class such that it always
I'm just starting Java ... again. I just made a simple program class first
This is my simple program: public class Test { public static Object obj =

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.