M
ma740988
///// 1
Consider the _FUNCTION_ template
template <typename T>
int spaceOf ()
{
int bytes = sizeof T;
return bytes / 4
+ bytes % 4 > 0;
}
Since C++ templates requires more intelligence from the environment
'we' have to tell the compiler about the actualy type:
So now:
class C {};
typdef void (*ptrFun)(int);
int idx = spaceOf<C>();
int jdx = spaceOf<ptrFunc>();
Except how do i achieve the same feat here for this fuction template:
class D {
public:
template<typename T> // here we go again....
D( T& t, void(T::*f)() )
{}
};
class UseD {
void someSpecialFunc() {};
D *ptrD;
public:
UseD() {
ptrD = new (std::nothrow) D(*this, &UseD::someSpecialFunc);
// validate
}
};
////////////// 2
For starters this is a 'C' ism and I suspect (scanned the ISO C++
standard and couldn't find anything) both are legal (compiler didn't
complain)?
a. typedef _MYSTRUCT {} MYSTRUCT;
b. typedef MYSTRUCT {} MYSTRUCT;
b at first appeared 'troubling' to me when I first encounted this and -
admittidely - I thought the compiler would complain.
Consider the _FUNCTION_ template
template <typename T>
int spaceOf ()
{
int bytes = sizeof T;
return bytes / 4
+ bytes % 4 > 0;
}
Since C++ templates requires more intelligence from the environment
'we' have to tell the compiler about the actualy type:
So now:
class C {};
typdef void (*ptrFun)(int);
int idx = spaceOf<C>();
int jdx = spaceOf<ptrFunc>();
Except how do i achieve the same feat here for this fuction template:
class D {
public:
template<typename T> // here we go again....
D( T& t, void(T::*f)() )
{}
};
class UseD {
void someSpecialFunc() {};
D *ptrD;
public:
UseD() {
ptrD = new (std::nothrow) D(*this, &UseD::someSpecialFunc);
// validate
}
};
////////////// 2
For starters this is a 'C' ism and I suspect (scanned the ISO C++
standard and couldn't find anything) both are legal (compiler didn't
complain)?
a. typedef _MYSTRUCT {} MYSTRUCT;
b. typedef MYSTRUCT {} MYSTRUCT;
b at first appeared 'troubling' to me when I first encounted this and -
admittidely - I thought the compiler would complain.