|
-
Dec 27th, 2001, 06:59 AM
#1
Thread Starter
Addicted Member
Class question - solved
Why do I have to have these things that are marked in bold below in the code?
Code:
class keeper
{
private:
int hours;
int minutes;
public:
keeper();
keeper(int s, int p);
void addKeeper(int, int);
void writeKeeper(keeper &k);
keeper getKeeper(keeper &h, char *name); keeper operator+(const keeper &k) const;
void show();
~keeper() {};
};
.
.
.
keeper keeper::getKeeper(keeper &h, char *name)
{
ifstream fin;
fin.open(name);
for(int i=0;i<3;i++)
{
switch(i)
{
case 0: fin >> h.hours;
break;
case 1: fin >> h.minutes;
break;
}
}
fin.close();
return h;
}
I know I can't have void keeper::........, but why do I have to have keeper beofre the code?
thanx
Last edited by [praetorian]; Dec 28th, 2001 at 05:29 PM.
[p r a e t o r i a n]
-
Dec 27th, 2001, 07:27 AM
#2
Monday Morning Lunatic
You're returning a copy of a reference already passed into the function 
Either take out the reference being passed, or change it to a void. When you pass a reference you can change it from the function.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Dec 27th, 2001, 03:41 PM
#3
transcendental analytic
I think you should have keeper& as return value
It's quite useful when building expresions with the sideeffect-paradigm
For instance:
char source[10]="something";
char* copy=strncpy(new char[10],source,10);
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 27th, 2001, 05:09 PM
#4
Thread Starter
Addicted Member
Problem solved thanks to Kedaman and Parksie, thank you!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|