static-cast

    3热度

    2回答

    我打算在我的随机数生成器中对我的数字使用math.h。看来,我只能在双打上使用math.h函数。所以: 我想给“价值”的价值“currentValue”,或至少部分数值的价值转移。我正在使用随机数字发生器,所以我不在乎整个号码是否被转移。我只需要它的一部分工作。 我在某个时刻: int currentValue; double value; **通过代码未显示它们的值设置。 ** 后来,我需

    0热度

    3回答

    我有一个数组,它保存对平淡的基类型的引用,我们称之为Object。 我从Object和Class2从Class1派生Class1。 #include <vector> class Object {}; class Class1 : public Object { public: virtual std::string ToString() {return "it is 1";} };

    7热度

    2回答

    我在问题提出here后问这个问题。 这一点很简单。假设你有两个类这样的: template < class Derived > class Base { ... operator const Derived&() const { return static_cast< const Derived& >(*this); } ... }; class Speciali

    9热度

    1回答

    At a reply of a blog post of Raymond Chen, 甲提问指出 雷蒙德,相信C++的例子是不正确的,因为在派生类的基类子对象的位置 根据ISO C++ 2003标准是不确定的 (10-3,第168页),并且您假定 基类子对象始终处于开头。在C++中,C 的例子也不错,所以我会坚持下去。 雷蒙德说 [代码不会做这样的假设。这就是为什么 使用static_cast代替

    2热度

    1回答

    template <class T> void MyClass<T>::MyMethod() { // ... // Which of the following initialization is better? T MyVariable1 = 1; // 1st T MyVariable2 = 2.0; // 2nd T M

    4热度

    4回答

    Prerequisities: 要理解这个问题,请阅读以下问题和它的答案起初: Cast auto_ptr<Base> to auto_ptr<Derived> 在 Cast auto_ptr<Base> to auto_ptr<Derived>史蒂夫回答说:“你的static_cast会将auto_ptr复制到一个临时的,所以aS将被重置,当临时(在语句结束时)资源将被销毁。“ 我对临时创建过程

    2热度

    1回答

    我试图将一些VC 6.0 C++代码转换为C#。具体来说,我解析通过二进制dat文件,我碰到的一个问题将这段代码: ar.GetFile()->Read(buf,sizeof(int)); memmove(&x,buf,4); pEBMA->before_after = static_cast<enum EBMA_Reserve>(x); pEBMA->method = static_c

    0热度

    1回答

    您好IM编码存储在一个int在C++中,我需要一些帮助,转换双为int。 需要什么才能从双倍(即3.5945)“3”中获得第一个数字。 并将该数字放入一个int。 我现在使用的static_cast和它返回一个0 double X = 3.1234; double Y = 4.3455; int myIntX = static_cast <int>(X); int myIntY = sta

    1热度

    1回答

    我想实现一类数字向量。我使用Qt模板QVector这类似于STL矢量 typedef float ArithmeticF; typedef QVector<ArithmeticF> VectorFloat; class VectorF : public VectorFloat { /// appends the rightSide to the end VectorF& operato

    0热度

    3回答

    我尝试实现static_cast的函子版本,以便在std::bind()中使用。 我知道Boost ll_static_cast<K>()(请参阅using static_cast with boost::bind),但我现在没有使用Boost。 有在Why do several of the standard operators not have standard functors?一个代码示例