Classy question
First of all, I''d like to say that I think I know C++ pretty damn well, but this is about the only [basic] thing that I am stumped on. Whenever I have a class with either protected or private members that looks something like this:
class MyClass
{
private:
int x;
void stuff();
};
And then I try to do this:
MyClass joe;
joe.stuff();
It gives me gay errors, something like "Cannot access private member stuff()" or something like that. The only way that I could figure to get around this was to replace "private" with "public." Am I overlooking something extremely obvious, or does MS strike again ? Just in case you''re wondering, I''ve got VC++ 6.0 proffessional edition. Thanks for the help.
If you code it, they will come...
Commander M
http://commanderm.8m.com
cmndrm@commanderm.8m.com
Hi,
Of course it shouldn''t work (MS are not to blame this time.
The function/method can only be called by member-methods of the class, coz you declare them private, something to do with the name or?
When you declare them public: then any function can call them regardless of membership or not.
Ok thats basic, then there are derivedclasses and more... that can "alter" access.
Newbie
Of course it shouldn''t work (MS are not to blame this time.
The function/method can only be called by member-methods of the class, coz you declare them private, something to do with the name or?
When you declare them public: then any function can call them regardless of membership or not.
Ok thats basic, then there are derivedclasses and more... that can "alter" access.
Newbie
/Mankind gave birth to God.
Thats because Private functions are only to be accessed from in the class.. Think of them as Internal functions. The Public functions uses them internally, but outsiders arent supposed to use private members.
If you have a Public function named GetSetting(), and a private function named OpenSettingsFile().. You''ll never call OpenSettingsFile() directly, because the class will always take care of it.
I suppose thats a poor example, but it should give you the picture of what I mean.
-Dan Smith
dans@3dgamedev.com
If you have a Public function named GetSetting(), and a private function named OpenSettingsFile().. You''ll never call OpenSettingsFile() directly, because the class will always take care of it.
I suppose thats a poor example, but it should give you the picture of what I mean.
-Dan Smith
dans@3dgamedev.com
D. Smith
Oh, ok. I think I get it. So lets say I had this:
class TheClass
{
public:
void func();
private:
void daFunc();
};
I could use daFunc() something like this?:
TheClass::func()
{
//Stuff here
daFunc();
//More stuff...
}
Assuming this is right, thanks for the response.
If you code it, they will come...
Commander M
http://commanderm.8m.com
cmndrm@commanderm.8m.com
class TheClass
{
public:
void func();
private:
void daFunc();
};
I could use daFunc() something like this?:
TheClass::func()
{
//Stuff here
daFunc();
//More stuff...
}
Assuming this is right, thanks for the response.
If you code it, they will come...
Commander M
http://commanderm.8m.com
cmndrm@commanderm.8m.com
Hi,
Yes, you got it!
now you can use:
Theclass sp;
sp.func(); // to call dfunc() if you want
Newbie
Yes, you got it!
now you can use:
Theclass sp;
sp.func(); // to call dfunc() if you want
Newbie
/Mankind gave birth to God.
You know C++ pretty damn well but yet you don''t grasp even the most basic concepts of classes? This is really scaring me...
Actually for someone who has learned C++ by themselves, I guess that''s an easy thing to miss.
Though, CmndrM, I wouldn''t assume you know THAT much about C++ yet, there are a lot of tricky things you might run into sooner or later.
( Inheritance, polymorphism, templates... )
~ Mad Keith ~
**SoftwareMode**
Though, CmndrM, I wouldn''t assume you know THAT much about C++ yet, there are a lot of tricky things you might run into sooner or later.
( Inheritance, polymorphism, templates... )
~ Mad Keith ~
**SoftwareMode**
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.
No, Keith, I actually can do that. It''s just that classes were something that I basically had to teach myself (I actually did very little reading to figure it out -- more trial and error in coding instead) to figure it out. That was pretty much the only thing that I didn''t quite get.
By the way, Staffan, if you ever need help in something that I think is basic, don''t expect me to be of any help but instead to laugh at you and make fun of you. Just because something is basic to you doesn''t mean everyone else will understand it. There''s this thing called quantam mechanics. I bet you don''t understand that much at all. Or how about relativity? I understand that, but there are a lot of people who don''t and I don''t make fun of them because I realize that at one point, I knew about as much as they did too. Besides, you can''t ever expect to get help from people if you just make fun of them.
For all the rest of you, thanks for the help, and sorry for my ranting.
If you code it, they will come...
Commander M
http://commanderm.8m.com
cmndrm@commanderm.8m.com
By the way, Staffan, if you ever need help in something that I think is basic, don''t expect me to be of any help but instead to laugh at you and make fun of you. Just because something is basic to you doesn''t mean everyone else will understand it. There''s this thing called quantam mechanics. I bet you don''t understand that much at all. Or how about relativity? I understand that, but there are a lot of people who don''t and I don''t make fun of them because I realize that at one point, I knew about as much as they did too. Besides, you can''t ever expect to get help from people if you just make fun of them.
For all the rest of you, thanks for the help, and sorry for my ranting.
If you code it, they will come...
Commander M
http://commanderm.8m.com
cmndrm@commanderm.8m.com
CmndrM - What I said was simply because you said you knew C++ "pretty damn well". I never said I'm a C++ guru. Nor did I state I know anything about quantam mechanics. I'm sorry if I offended you. It just kind of bugs me with all these 3l33t super hacker kids (guess you're not one of them after all ) that says they are going to found the best game development company in the US and make the next quake. I think you know what I'm talking about.
"I think, therefore I am...I think"
Edited by - Staffan on 3/18/00 5:11:11 PM
"I think, therefore I am...I think"
Edited by - Staffan on 3/18/00 5:11:11 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement