is this a POD?
template <class T>
struct Data {
float val_f;
T val_t;
int val_i;
};
If i have a C function that requires something like:
struct Data {
float val_f;
double val_t;
int val_i;
};
can i pass instead a Data<double>
object?
Ps.
I guess the answer is yes, since at compile time the Data<dobule>
would be translated to the structure above and would be a POD structure.
I need just and (informed) confirmation on this.
In answer to the first question, it depends on the template parameter T
. Data<T>
will be POD if T
is POD.
In answer to your second question, classes with identical definitions are not identical types so you can't use them interchangeably. Data<double>
in the first example would not be the same type as Data
in your second definition. (To have them in the same program you would have to give them different names, anyway. You can't have a template with the same name as a class.)
It depends on what type you're passing as T
. If you're instantiating with a POD
type, then yes.
If you have access to c++0x
or Boost you should be able to check via the trait std::is_pod<mytype>
.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With