I've Got A problem On Referencing Functions

I

iman.sharafodin

Hello all u guys out there

Ive got a problem Undrestanding in example what it means

class point
{
....
}


point &function1()
{
point sample;
return sample;
}

whats meaning of & in a function??

Tank you
 
A

Alf P. Steinbach

* (e-mail address removed):
Hello all u guys out there
"you"


Ive got a problem Undrestanding in example what it means

missing apostrophe, uppercase U, "understanding"

class point
{
...
}

missing semicolon

point &function1()
{
point sample;
return sample;
}

for a newbie this function constitutes an error

whats meaning of & in a function??

missing apostrophe, extranous question mark

the meaning of "&" depends on the context; consult your nearest C++
textbook.
 
I

iman.sharafodin

i'm not good in english...
then accept my Apologize

in example in file below if you clean & before operator you got an
error
why it couldn't answer when we erase & ?

//phonenumber.h

#ifndef PHONENUMBER_H
#define PHONENUMBER_H

#include <iostream>
using std::eek:stream;
using std::istream;

#include <string>
using std::string;

class PhoneNumber
{
friend ostream &operator<<( ostream &, const PhoneNumber & );
friend istream &operator>>( istream &, PhoneNumber & );
private:
string areaCode; // 3-digit area code
string exchange; // 3-digit exchange
string line; // 4-digit line
}; // end class PhoneNumber

#endif

----------------
//PhoneNumber.cpp

#include <iomanip>
using std::setw;

#include "PhoneNumber.h"

// overloaded stream 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; // enables cout << a << b << c;
} // end function operator<<

// overloaded stream extraction operator; cannot be
// a member function if we would like to invoke it with
// cin >> somePhoneNumber;
istream &operator>>( istream &input, PhoneNumber &number )
{
input.ignore(); // skip (
input >> setw( 3 ) >> number.areaCode; // input area code
input.ignore( 2 ); // skip ) and space
input >> setw( 3 ) >> number.exchange; // input exchange
input.ignore(); // skip dash (-)
input >> setw( 4 ) >> number.line; // input line
return input; // enables cin >> a >> b >> c;
} // end function operator>>

Tanx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top