cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
how to overload (int) for my class?
how to overload (int) for my class?
Apr 26, 2010 at 10:36am UTC
rautumn
(1)
Hi I have a class that it have an integer attribute and I want when it typed for example :
class myclass{
private:
int salary;
}
int main(){
myclass o();
int x =(int) o;
}
x get loaded with o.salary;
please tell me what should I do?
Apr 26, 2010 at 11:03am UTC
attaboy
(72)
I don't really get your question there.... repost pls...
Apr 26, 2010 at 12:35pm UTC
Bazzy
(6281)
You can overload the conversion operator:
1
2
3
4
operator
int
()
const
{
return
salary; }
( member of the class )
Topic archived. No new replies allowed.