Can the arguments of main's signature in C++ have the unsiged and const qualifiers?

This question already has an answer here: What should main() return in C and C++? 19 answers The C++98 standard says in section 3.6.1 paragraph 2 An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a return type of type int , but otherwise its type is implementation-defined. All implementations shall allow both the following defi

C ++中main的签名参数是否具有unsiged和const限定符?

这个问题在这里已经有了答案: main()应该在C和C ++中返回什么? 19个答案 C ++ 98标准在第3.6.1节第2段中说过 一个实现不应该预定义主函数。 该功能不得超载。 它应该有一个类型为int的返回类型,否则它的类型是实现定义的。 所有的实现都应该允许main的以下定义: int main()和int main(int argc, char* argv[]) 所以这个标准没有规定env接受main是可以接受的,但它是允许的。 因为这是经常提到的,这里是前面

Difference between void main and int main?

This question already has an answer here: What should main() return in C and C++? 19 answers The difference is one is the correct way to define main , and the other is not. And yes, it does matter. int main(int argc, char** argv) or int main() is the proper definition of your main per the C++ spec. void main(int argc, char** argv) is not and was, IIRC, a perversity that came with M

void main和int main之间的区别?

这个问题在这里已经有了答案: main()应该在C和C ++中返回什么? 19个答案 区别在于一个是定义main的正确方法,另一个不是。 是的,这很重要。 int main(int argc, char** argv) 要么 int main() 是每个C ++规范的main定义。 void main(int argc, char** argv) 并不是,IIRC是微软C ++编译器带来的一种变态。 https://isocpp.org/wiki/faq/newbie#main-returns-int Bjarne Stroustrup非常清楚地表达了这一

cast or C Style type casting

This question already has an answer here: When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used? 6 answers Casts should be used rarely, and cautiously, and it is a lot easier to spot when you're abusing the system if you write: char *x = const_cast<char *>(some_const_char_pointer_expression); than if you disguise it with: char *x = (char *)some_const_cha

演员表或C风格类型演员

这个问题在这里已经有了答案: 什么时候应该使用static_cast,dynamic_cast,const_cast和reinterpret_cast? 6个答案 演员应该很少使用,并且小心谨慎,如果你写作时滥用系统会更容易发现: char *x = const_cast<char *>(some_const_char_pointer_expression); 比如果你掩饰它: char *x = (char *)some_const_char_pointer_expression; 因此,使用明确的,受控制的,详细的表示法是因为它鼓励您避免强制转换,

Acceptable example of when to use a dynamic

This question already has an answer here: When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used? 6 answers @user997112 [edit at bottom] Hello. Below we use a collection of random polymorphic pointers with common ancestor through the common interface. Additional work is done with one of the particular derived classes we need dynamic_cast or typeid to know t

什么时候使用动态的可接受示例

这个问题在这里已经有了答案: 什么时候应该使用static_cast,dynamic_cast,const_cast和reinterpret_cast? 6个答案 @ user997112 [在底部编辑] 你好。 下面我们使用具有共同祖先的随机多态指针集合 通过通用接口。 额外的工作是使用其中一个特定派生类完成的 我们需要dynamic_cast或typeid来了解这个.... 主要功能有呼叫 然后是类声明 那么动态演员阵容就结束了 没有显示用new创建的对象的删除 #incl

What is the benefit/use of dynamic

This question already has an answer here: What is the advantage of using dynamic_cast instead of conventional polymorphism? 5 answers When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used? 6 answers If you were to not use a cast, then non-virtual member functions would be calling Base methods. The following code shows the difference between the virtual and non-vi

动态的好处/用处是什么?

这个问题在这里已经有了答案: 使用dynamic_cast代替传统的多态性有什么优势? 5个答案 什么时候应该使用static_cast,dynamic_cast,const_cast和reinterpret_cast? 6个答案 如果你不使用强制转换,那么非虚拟成员函数就会调用Base方法。 以下代码显示了虚函数和非虚函数之间的区别,以及动态转换后会发生什么。 class Base { public: void print2() { cout << "Base" << endl; } vi

What is the purpose of reinterpret

This question already has an answer here: When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used? 6 answers reinterpret_cast<T>() forces a given bit-pattern to be interpreted as the type you desire. It is the most "brutal" among casts. From MSDN: Allows any pointer to be converted into any other pointer type. Also allows any integral >type to

重新解释的目的是什么?

这个问题在这里已经有了答案: 什么时候应该使用static_cast,dynamic_cast,const_cast和reinterpret_cast? 6个答案 reinterpret_cast<T>()强制给定的位模式被解释为你想要的类型。 这是演员中最“残酷”的。 来自MSDN: 允许将任何指针转换为任何其他指针类型。 还允许任何整型>类型转换为任何指针类型,反之亦然。 滥用reinterpret_cast操作符可能很不安全。 除非期望的>转换本质上是低级别的,否则

cast not needing to perform a run

This question already has an answer here: When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used? 6 answers class Base { public: virtual ~Base() {} // ... }; class Derived : public Base { // ... }; "Typical use": void foo(Derived*); void f(Base* pb) { if (Derived* pd = dynamic_cast<Derived*>(pb)) { foo(pd); } } "Abo

不需要执行运行

这个问题在这里已经有了答案: 什么时候应该使用static_cast,dynamic_cast,const_cast和reinterpret_cast? 6个答案 class Base { public: virtual ~Base() {} // ... }; class Derived : public Base { // ... }; “典型用途”: void foo(Derived*); void f(Base* pb) { if (Derived* pd = dynamic_cast<Derived*>(pb)) { foo(pd); } } “以上报价”: void bar(Base*); void f(Der

C++ Casting Operators and traditional C casting operators

Possible Duplicate: When should static_cast, dynamic_cast and reinterpret_cast be used? I have done a lot of googling to find about: why to use C++ casting operators over traditional C style casting operators? When to use C++ casting operators, some live examples? The following is what I found: Traditionally any C++ casting operators is used for better maintenance of your code (ie) we

C ++铸造操作员和传统的C铸造操作员

可能重复: 什么时候应该使用static_cast,dynamic_cast和reinterpret_cast? 我做了大量的搜索以查找关于: 为什么要使用C ++铸造操作符而不是传统的C样式铸造操作符? 何时使用C ++转换运算符,一些实例? 以下是我发现的: 传统上,任何C ++铸造操作符都用于更好地维护您的代码(即),与C风格铸造操作符不同,我们可以通过仅搜索复杂表示法(reinterpret_cast <)来轻松找到在代码中使用铸造的位置。 现在

Best practice in C++ for casting between number types

This question already has an answer here: When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used? 6 answers Just use static_cast . The problem with C casts is the ambiguity of the operation (ie point (1) of Explicit type conversion). C++ casts avoid this. Additionally C++ casts are more visible when searching for them. Using Stroustrup's words (What good is

C ++中用于在数字类型之间进行转换的最佳实践

这个问题在这里已经有了答案: 什么时候应该使用static_cast,dynamic_cast,const_cast和reinterpret_cast? 6个答案 只需使用static_cast 。 C剧本的问题是操作的模糊性(即显式类型转换的点(1))。 C ++强制避免这种情况。 此外,C ++强制转换在搜索时更为明显。 使用Stroustrup的话(static_cast有什么好处?): 如果在开发或维护过程中涉及的其中一种类型发生变化,那么即使是无辜的演员阵容也会成为一个严

C++ Polymorphism: from parent class to child

This question already has an answer here: When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used? 6 answers "but is there any way to convert it back: from parent, which was obtained from child, give child class back?" Yes, as mentioned in the other answers, there are two ways to do this. Child * old_child = dynamic_cast<Child*>(parent); The result

C ++多态性:从父类到子类

这个问题在这里已经有了答案: 什么时候应该使用static_cast,dynamic_cast,const_cast和reinterpret_cast? 6个答案 “但是有什么办法可以将它转回来:从父母那里得到的,是从孩子那里得到的,给孩子上课呢?” 是的,正如其他答案中提到的那样,有两种方法可以做到这一点。 Child * old_child = dynamic_cast<Child*>(parent); dynamic_cast<>的结果可以在运行时检查,因此您可以确定parent对象是否确实代