Hi,
is it possible to return the sizeof a derived class already from base class/struct?
imho the size of a class is a kind of property of itself, like the weight of a human being. But I don't want to write the same function in every class.
many thanks in advance
Oops
PS: so code to make my question more clear:
template <typename T>
struct StructBase {
size_t size<T>(){
return sizeof(T);
}
};
struct MyStruct: public StructBase<MyStruct> {
double d1;
double d2;
double d3;
MyStruct(): d1(0), d2(0), d3(0){}
//I do not want to do this here
//size_t size(){ //return size<MyStruct> ;}
};
int main(void) {
MyStruct m;
std::cout << m.size(); //nop ?!?
}