VC中如何返回某个变量的类型,就像C中的 typeof(&oldvar) newvar,在VC中如何写??
VC编译器不认typeof,急用。

解决方案 »

  1.   

    我想实现一个类似模板,但是比较easy,就是根据某个变量的类型来定义相同类型的变量.
      

  2.   

    typedef DataType int;DataType var; // 是这样?
      

  3.   

    问题是我根本不知道 将要定义的变量地类型,需要动态的定义 .
    typeof 得到当前变量类型.然后像我写地那样生成该类型地变量.
      

  4.   

    注意一下,是typeof  不是typedef
      

  5.   

    :)
    我不想搞地那样麻烦,想easy一些,我看的C代码.
      

  6.   

    typeid( type-id )typeid( expression )
      

  7.   

    typeid Operator
    C++ Specific —>typeid( type-id )typeid( expression )The typeid operator allows the type of an object to be determined at run-time.The result of a typeid expression is a const type_info&. The value is a reference to a type_info object that represents either the type-id or the type of the expression, depending on which form of typeid is used. See type_info Class for more information.END C++ Specific
    ///////////////////////////////////////////////////////////////
    type_info Class
    C++ Specific —>The type_info class describes type information generated within the program by the compiler. Objects of this class effectively store a pointer to a name for the type and an encoded value suitable for comparing two types for equality or collating order. The encoding rules and collating sequence for types are unspecified and may differ between programs.class type_info {
    public:
       virtual ~type_info();
       int operator==(const type_info& rhs) const;
       int operator!=(const type_info& rhs) const;
       int before(const type_info& rhs) const;
       const char* name() const;
       const char* raw_name() const;
    private:
       ...
    };
    Note   You must include the typeinfo.h header file in order to use the type_info class.END C++ Specific
      

  8.   

    int nNum = 0
    int *pNum = &nNum;
    cout << typeid(pNum).name() << endl;// output is:
    // int *
      

  9.   

    忘了,老兄 我光顾的高兴了。 但是我如何typeof(&oldvar) newvar这样定义呢???
    我这样typeid(&nNum).name()  shi;编译器还是不认呀 !!!!