test.h
来自「c#设计模式WithCla」· C头文件 代码 · 共 125 行
H
125 行
// Class: test //ANSI C++
#ifndef __TEST_H //Required for current class
#define __TEST_H
#ifndef __IOSTREAM_H //Required for cin and cout
#include <iostream.h>
#endif
class test
{
int registration; //Attribute data member
int size; //Attribute data member
int color; //Attribute data member
protected:
public:
//Default constructor alternative to compiler provided default constructor
//Ensure correct initial values
//Initialization list has members in the order declared
//Association object data member pointers initialized to null association object
test () : registration(0), size(0), color(0)
{
//Initialization of array of 1:M association objects to null association objects
}
//Constructor with arguments
//Update to argument list to initialize base class data members,
//e.g. (int aNumber) : BaseClass (aNumber)
test ( int aregistration, int asize, int acolor )
{
registration = aregistration;
size = asize;
color = acolor;
//Initialization of array of 1:M association objects to null association objects
}
//Copy constructor alternative to compiler provided default copy constructor
//Copy alternatives for association objects: (1) initialize association object to nullAssociation Object
//(2) Shallow copy to copy pointers of association objects (3) Deep copy to create new association objects
//and copy values of association objects
//Commented out code assigns 1:1 and 1:M association object data member pointers for shallow copy
//Remove // if you desire to assign pointers
test (const test& atest )
{ int i = 0;
registration = atest.registration;
size = atest.size;
color = atest.color;
}
//Operator= Assignment Operator alternative to compiler provided default operator=
//If base class make virtual
//Assignment alternatives for association objects: (1) initialize association object to nullAssociation Object
//(2) Shallow copy to copy pointers to association objects (3) Deep copy to create new association objects
//and copy values of association objects
//Commented out code assigns 1:1 association object data member pointers for shallow copy
//Remove // if you desire to assign association object pointers for shallow copy
test& operator= (const test& atest);
//Operator== Equality Operator - No compiler default operator== generated
//If base class make virtual
//Update to access 1:1 association object data members
//Function does not compare 1:1 and 1:M association object data member pointers
int operator== (const test& atest) const;
//Operator<< for cout
friend ostream& operator<< (ostream& os, test& atest);
//Operator>> for cin
friend istream& operator>> (istream& is, test& atest);
//Get accessor function for non-static attribute data member
int getregistration() const
{ return registration;
}
//Get accessor function for non-static attribute data member
int getsize() const
{ return size;
}
//Get accessor function for non-static attribute data member
int getcolor() const
{ return color;
}
//Set accessor function for non-static attribute data member
void setregistration (const int aregistration)
{ registration = aregistration;
}
//Set accessor function for non-static attribute data member
void setsize (const int asize)
{ size = asize;
}
//Set accessor function for non-static attribute data member
void setcolor (const int acolor)
{ color = acolor;
}
void start () ;
void stop () ;
void great () ;
~ test ( ) { } //Destructor - Delete any pointer data members that used new in constructors
//Destructor should be virtual if and only if class contains at least one virtual function
//Objects destroyed in the reverse order ot the construction order
};
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?