ok, if you were to put a function inside of a protected class, you can't access it outside of that class, right?
ok, if you were to put a function inside of a protected class, you can't access it outside of that class, right?
This has been a public service announcement from GOD.
111 1111
err.. wrong forum by any chance?!
[edit]thats better
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
If you mean when you put a function in the protected section of a class who can access it then the answer is that class and its derived classes. The function may not be accessed from outside the class because it is protected and not public.
Code:class AClass { public: // Our classes interface. These can be called from anywhere. protected: // This is like private except is visible in derived classes. private: // This is our class internals. Accessible by the class only. };
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
ok, but in the tutorial for this site, they have as an example:
Computer();
~Computer();
void setspeed(int p);
int readspeed();
the class
protected:
int processorspeed;
};
Computer::Computer()
{
processorspeed = 0;
}
shouldn't the variable processorspeed not be able to be accessed in computer::computer()?
of course it can as Computer::Computer is a member of the class. Its the constructor. Be a bit silly having a constructor that couldnt construct the class object wouldnt it?! so of course it has full access to all of the class.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
Originally posted by Stoned_Coder
of course it can as Computer::Computer is a member of the class. Its the constructor. Be a bit silly having a constructor that couldnt construct the class object wouldnt it?! so of course it has full access to all of the class.
Oh, because computer is a function in computer, I didn't realize that. Thanks! by the way, I am just learning classes as we speak.
This has been a public service announcement from GOD.
111 1111
if you understand private members, I can tell you that protected members are the same exept for derived classes, derived classes can access protected members, and cann't access private ones.
none...
I don't know if I would really call a constructor a function. it may be, correct me if I'm wrong please. It kindof seems like a function, but to be technical, a constructor and a member function of the class are two different things. it doesn't seem to be a function because constructors don't return anything.Originally posted by sentienttoaster
Oh, because computer is a function in computer, I didn't realize that. Thanks! by the way, I am just learning classes as we speak.
Constructors do return values....
Think about one of the scenaries in which a copy constructor is automatically invoked: When you are returning a class type object from a function.
Code:myClass myClass::myFunction() { // blahblahblah return (myClass(/* What goes here */)); // the constructor returns a value of type myClass }