Unicorn with delicious cookie
Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter
to the top
>
>
>
The function of printing an expression'…

The function of printing an expression's type

20 Jul 2009
Author:

I very often meet debates in forums on what type this or that expression will have. So I decided to make a little note in the blog to refer to this.

An example of code printing the type of an expression and information about it:

#include <iostream>
using namespace std;
template <typename T>
void PrintTypeInfo(char const* description, T)
{
  const type_info &info = typeid(T);
  cerr << "\"" << description << "\":"
       << " type = " << info.name()
       << "; sizeof = " << sizeof (T)
       << "; alignof = " << __alignof (T)
       << endl;
}
int _tmain(int, _TCHAR *[])
{
  char c1 = 0, c2 = 0;
  PrintTypeInfo("char + char", c1 + c2);
}

The result:

"char + char": type = int; sizeof = 4; alignof = 4
Popular related articles

S'abonner

Comments (0)

close comment form
close form

Remplissez le formulaire ci‑dessous en 2 étapes simples :

Vos coordonnées :

Étape 1
Félicitations ! Voici votre code promo !

Type de licence souhaité :

Étape 2
Team license
Enterprise licence
** En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité
close form
Demandez des tarifs
Nouvelle licence
Renouvellement de licence
--Sélectionnez la devise--
USD
EUR
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
La licence PVS‑Studio gratuit pour les spécialistes Microsoft MVP
close form
Pour obtenir la licence de votre projet open source, s’il vous plait rempliez ce formulaire
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
I want to join the test
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
check circle
Votre message a été envoyé.

Nous vous répondrons à


Si l'e-mail n'apparaît pas dans votre boîte de réception, recherchez-le dans l'un des dossiers suivants:

  • Promotion
  • Notifications
  • Spam