You should include<string.h> if you want use memset.
void memset(void* ptr, int val, size_t num);
val: unsigned char conversion.
num: number of bytes.
So, memset can only be used while setting value to zero.
2. sizeof
Yields the size of its operand with respect to the size of type char.
char - 8 bit
byte - 8 bit
int - 32 bit
3. If you want to declare a template function.
template<class TYPE>
void PrintTwice(TYPE data)
{
cout<<"Twice: " << data * 2 << endl;
}
template<class T1, class T2, class T3>
T2 DoSomething(const T1 tArray[], T2 tDefaultValue, T3& tResult)
{
...
}
For class:
template<class T>
class Item
{
T Data;
public:
Item() : Data( T() )
{}
void SetData(T nValue)
{
Data = nValue;
}
T GetData() const
{
return Data;
}
void PrintData()
{
cout << Data;
}
};
If you want to use Item: Item<int> intitem;
No comments:
Post a Comment