title: using declarations in main (C++)
body: <p>Although you wouldn't want to do this, if you have a namespace COMPANY, and a class in that namespace SOMECLASS.  Why is it that in the .cpp file, you might define the functions as</p>
  
  <pre><code>COMPANY::SOMECLASS::someFunction()
  {}
  </code></pre>
  
  <p>But in main, I get errors for doing:</p>
  
  <pre><code>int main() {
    COMPANY::SOMECLASS::someFunction();
  }
  </code></pre>
  
  <p>but instead you declare the namespace and do something like:</p>
  
  <pre><code>using COMPANY::SOMECLASS;
  
  int main() {
    someFunction();
  }
  </code></pre>
  
  <p>My compile errors are:</p>
  
  <pre><code>1&gt;c:\documents and settings\wongj\desktop\main.cpp(14) : error C2065: 'saver1' : undeclared identifier
  1&gt;c:\documents and settings\wongj\desktop\main.cpp(14) : error C2277: 'JWong::SavingsAccount::{ctor}' : cannot take address of this member function
  1&gt;c:\documents and settings\wongj\desktop\main.cpp(14) : error C2061: syntax error : identifier '{ctor}'
  </code></pre>
  
  <p>SavingsAccount.cpp:</p>
  
  <pre><code>#include "SavingsAccount.h"
  
  // initialize static data member
  double JWong::SavingsAccount::annualInterestRate = 0;
  
  // 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-&gt;savingsBalance = savingsBalance;
  }
  
  // added these functions to make program cleaner
  double JWong::SavingsAccount::getMonthlyInterest()
  {
      return monthlyInterest;
  }
  
  void JWong::SavingsAccount::setMonthlyInterest(double monthlyInterest)
  {
      this-&gt;monthlyInterest = monthlyInterest;
  }
  
  // returns monthly interest and sets savingsBalance to new amount
  double JWong::SavingsAccount::calculateMonthlyInterest()
  {
      double monthlyInterest = savingsBalance * SavingsAccount::annualInterestRate / 12; 
      setSavingsBalance(savingsBalance + monthlyInterest);
      setMonthlyInterest(monthlyInterest);
      return monthlyInterest; 
  }
  
  void JWong::SavingsAccount::modifyInterestRate(double newInterestRate)
  {
      SavingsAccount::annualInterestRate = newInterestRate;
  }
  
  double JWong::SavingsAccount::getAnnualInterestRest()
  {
      return SavingsAccount::annualInterestRate;
  }   
  </code></pre>
  
  <p>SavingsAccount.h</p>
  
  <pre><code>#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();
          double getMonthlyInterest();
          void setMonthlyInterest(double monthlyInterest);
  
          // static functions
          static void modifyInterestRate(double newInterestRate);
          static double getAnnualInterestRest();
      private:
          double savingsBalance;
  
          // static members
          static double annualInterestRate; 
          double monthlyInterest;
      };
  }
  
  
  
  #endif
  </code></pre>
  
  <p>main.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  
  #include "SavingsAccount.h"
  using std::cout;
  using std::setprecision;
  using std::fixed;
  //using JWong::SavingsAccount;
  
  int main()
  {
      JWong::SavingsAccount::SavingsAccount *saver1 = new JWong::SavingsAccount::SavingsAccount(2000.00);
  }
  </code></pre>