|
Last change
on this file since 1861 was 823, checked in by bird, 22 years ago |
|
more statics.
|
-
Property cvs2svn:cvs-rev
set to
1.2
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
-
Property svn:keywords
set to
Author Date Id Revision
|
|
File size:
1.2 KB
|
| Line | |
|---|
| 1 |
|
|---|
| 2 | class ParentClass
|
|---|
| 3 | {
|
|---|
| 4 | private:
|
|---|
| 5 | int iPrivate;
|
|---|
| 6 | static char *pszPrivateStatic;
|
|---|
| 7 |
|
|---|
| 8 | protected:
|
|---|
| 9 | int iProtected;
|
|---|
| 10 | static char *pszProtectedStatic;
|
|---|
| 11 |
|
|---|
| 12 | public:
|
|---|
| 13 | static char *pszPublicStatic;
|
|---|
| 14 | static long lPublicStatic;
|
|---|
| 15 | int iPublic;
|
|---|
| 16 |
|
|---|
| 17 | ParentClass()
|
|---|
| 18 | {
|
|---|
| 19 | iPublic = 1;
|
|---|
| 20 | iProtected = 2;
|
|---|
| 21 | iPrivate = 3;
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | virtual ~ParentClass()
|
|---|
| 25 | {
|
|---|
| 26 | iPublic = -1;
|
|---|
| 27 | iProtected = -2;
|
|---|
| 28 | iPrivate = -3;
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | virtual int get() const
|
|---|
| 32 | {
|
|---|
| 33 | return iProtected + iPrivate;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | virtual void set(int i)
|
|---|
| 37 | {
|
|---|
| 38 | iPublic = i;
|
|---|
| 39 | iProtected = i + 1;
|
|---|
| 40 | iPrivate = i + 2;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | int getPrivate(void)
|
|---|
| 44 | {
|
|---|
| 45 | return iPrivate;
|
|---|
| 46 | }
|
|---|
| 47 | };
|
|---|
| 48 | char *ParentClass::pszPrivateStatic = "PrivateStatic";
|
|---|
| 49 | char *ParentClass::pszProtectedStatic = "ProtectedStatic";
|
|---|
| 50 | char *ParentClass::pszPublicStatic = "PublicStatic";
|
|---|
| 51 | long ParentClass::lPublicStatic = 42;
|
|---|
| 52 |
|
|---|
| 53 | class ChildClass : public ParentClass
|
|---|
| 54 | {
|
|---|
| 55 | public:
|
|---|
| 56 | ChildClass(int &ri) :
|
|---|
| 57 | ParentClass()
|
|---|
| 58 | {
|
|---|
| 59 | ri = getPrivate();
|
|---|
| 60 | }
|
|---|
| 61 | };
|
|---|
| 62 |
|
|---|
| 63 | int main(void)
|
|---|
| 64 | {
|
|---|
| 65 | int i;
|
|---|
| 66 | ChildClass *pObj = new ChildClass(i);
|
|---|
| 67 | pObj->set(i+1);
|
|---|
| 68 | delete pObj;
|
|---|
| 69 | return 0;
|
|---|
| 70 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.