Неопределенная ссылка на оператор >>

Я пытаюсь работать над перегрузкой операторов, мой заголовочный файл состоит из:

#ifndef PHONENUMBER_H
#define PHONENUMBER_H

#include<iostream>
#include<string>
using namespace std;

class Phonenumber
{
    friend ostream &operator << ( ostream&, const Phonenumber & );
    friend istream &operator >> ( istream&, Phonenumber & );
private:
    string areaCode;
    string exchange;
    string line;

};

#endif // PHONENUMBER_H

И определение класса

//overload stream insertion and extraction operators
//for class Phonenumber
#include <iomanip>
#include "Phonenumber.h"
using namespace std;
//overloades stram insertion operator cannot be a member function
// if we would like to invoke it with
//cout<<somePhonenumber
ostream &operator << ( ostream &output, const Phonenumber &number)
{

    output<<"("<<number.areaCode<<")"
     <<number.exchange<<"-"<<number.line;
    return output;

}//end function opertaor <<

istream &operator >> ( istream &input, Phonenumber &number)
{
    input.ignore(); //skip (
    input>>setw(3)>>number.areaCode;//input areacode
    input.ignore(2);//skip ) and space
    input>>setw(3)>>number.exchange;//input exchange
    input.ignore();//skip -
    input>>setw(4)>>number.line;//input line
    return input;
}

вызова, выполняемого через main,

#include <iostream>
#include"Phonenumber.h"
using namespace std;

int main()
{
    Phonenumber phone;
    cout<<"Enter number in the form (123) 456-7890:"<<endl;
    //cin>> phone invokes operator >> by implicitly issuing the non-member function call operator>>(cin,phone)
    cin >> phone;
    //cout<< phone invokes operator << by implicitly issuing the non-member function call operator>>(cout,phone)
    cout << phone<<endl;
    return 0;
}

, но компиляция этого показывает мне ошибку компилятора: неопределенная ссылка на 'operator>>(std:istream&, Phonenumber&)' Может ли кто-нибудь помочь мне решить эту ошибку

7
задан Jonathan Wakely 22 June 2012 в 07:50
поделиться