간단한 코드의 링크에러의 이유를 모르겠습니다.

Geniys의 이미지

다음의 코드가 컴파일은 되나 링크시 다음과 같은 에러가 발생합니다.

그런데 도대체 모르겠군요 ㅠ,ㅠ

코드 부분

#include <iostream>

using namespace std;

class BankAccount
{
public:
  void set(int dollers, int cents, double rate);
  void set(int dollers, double rate);
  void update();
  double get_balance();
  double get_rate();
  void output(ostream& outs);
  double difference(BankAccount cn1, BankAccount cn2);

private:
  double balance;
  double interest_rate;
  double fraction(double percent);
};


int main()
{
  BankAccount account1, account2;
  cout << "Start of Test:\n";

  account1.set(123, 99, 3.0);
  cout << "account 1 initial statement:\n";
  account1.output(cout);

  account1.set(100, 5.0);
  cout << "account1 with new setup:\n";
  account1.output(cout);

  account1.update();
  cout << "account1 after update:\n";
  account1.output(cout);

  account2 = account1;
  cout << "account2:\n";
  account2.output(cout);

  cout << account1.difference(account1, account2) << endl;

  return 0;
}

double difference(BankAccount cn1, BankAccount cn2)
{
  return (cn1.get_balance() - cn2.get_balance());
}

void BankAccount::set(int dollers, int cents, double rate)
{
  if(dollers < 0 || cents < 0 || rate < 0)
    {
      cout << "Illegal values for money or interest rate.\n";
      exit(1);
    }

  balance = dollers + 0.01 * cents;
  interest_rate = rate;
}

void BankAccount::set(int dollers, double rate)
{
  if(dollers < 0 || rate < 0)
    {
      cout << "Illegal values for money or interest rate.\n";
      exit(1);
    }
  balance  = dollers;
  interest_rate = rate;
}

void BankAccount::update()
{
  balance = balance + fraction(interest_rate) * balance;
}

double BankAccount::fraction(double percent_value)
{
  return (percent_value/100.0);
}

double BankAccount::get_balance()
{
  return balance;
}

double BankAccount::get_rate()
{
  return interest_rate;
}

void BankAccount::output(ostream& outs)
{
  outs.setf(ios::fixed);
  outs.setf(ios::showpoint);
  outs.precision(2);
  outs << "Account balance $" << balance << endl;
  outs << "Interest rate " << interest_rate << "%" << endl;
}

에러부분

Quote:

Linking...
ConsoleTest.obj : error LNK2001: unresolved external symbol "public: double __thiscall BankAccount::difference(class BankAccount,class BankAccount)" (?difference@BankAccount@@QAENV1@0@Z)
Debug/ConsoleTest.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

ConsoleTest.exe - 2 error(s), 0 warning(s)

VC 6.0에서 컴파일 했습니다.

익명 사용자의 이미지

>> double difference(BankAccount cn1, BankAccount cn2)

double BankAccount::difference(BankAccount cn1, BankAccount cn2)

mykhs7200의 이미지

#include <iostream> 이 아니라
#include <iostream.h> 아닌가요?

Geniys의 이미지

어이가 없군요....

Quote:

double BankAccount::difference(BankAccount cn1, BankAccount cn2)
{
return (cn1.get_balance() - cn2.get_balance());
}

BankAccount 이것을 빼먹다니...

============================
A watched pot never boils

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.