nullptr

nullptr not declared in scope when compiling on mac

佐手、 提交于 2021-02-10 07:06:05
问题 I'm trying to use the "Yet Another PCInt Library" for enabling pin change interrupts on my Arduino mega 2560. In the Arduino IDE, the code compiles fine on windows, but fails on a mac. It gives an error code stating: nullptr not declared in this scope attachInterrupt(pin, (callback)func, nullptr, mode, trigger_now); ^ How can I get this to compile on OS X in the arduino IDE? 回答1: nullptr was introduced into the C++11 standard, and it does not exist in any earlier standards. My best guess is

nullptr not declared in scope when compiling on mac

懵懂的女人 提交于 2021-02-10 07:03:55
问题 I'm trying to use the "Yet Another PCInt Library" for enabling pin change interrupts on my Arduino mega 2560. In the Arduino IDE, the code compiles fine on windows, but fails on a mac. It gives an error code stating: nullptr not declared in this scope attachInterrupt(pin, (callback)func, nullptr, mode, trigger_now); ^ How can I get this to compile on OS X in the arduino IDE? 回答1: nullptr was introduced into the C++11 standard, and it does not exist in any earlier standards. My best guess is

Why can't nullptr convert to int?

你离开我真会死。 提交于 2021-02-06 09:58:47
问题 Summary: nullptr converts to bool , and bool converts to int , so why doesn't nullptr convert to int ? This code is okay: void f(bool); f(nullptr); // fine, nullptr converts to bool And this is okay: bool b; int i(b); // fine, bool converts to int So why isn't this okay? void f(int); f(nullptr); // why not convert nullptr to bool, then bool to int? 回答1: Because it is exactly the main idea of nullptr . nullptr was meant to avoid this behavior: struct myclass {}; void f(myclass* a) { std::cout

Can you compare nullptr to other pointers for order? Is it always smaller?

∥☆過路亽.° 提交于 2020-12-08 06:54:24
问题 This question is based on code that I found that monitors possible memory leaks, so it contains some code that you probably don't want to see in regular programs like ordering pointers. However, I saw that a pointer was set to nullptr and then the pointer was compared to a maximum address. Is it guaranteed by the C++ standard that nullptr is always smaller than other pointers for operator< ? 回答1: Can you compare nullptr to other pointers for order? Yes . But whether the result is useful is

Does any major C++ implementation actually define `NULL` as `nullptr`?

99封情书 提交于 2020-05-15 06:24:08
问题 Since C++11, the Standard allows the macro NULL to either be a integer literal with value zero, or a prvalue of type std::nullptr_t . Any Standard Library vendor deciding to change their definition of NULL from an integer to nullptr would very likely cause breakage for clients relying on pre-C++11 code. Does any major implementation (e.g. GCC, Clang, MSVC) actually define NULL as nullptr ? Or, despite the possibility, does nobody do this? 回答1: libstdc++ relies on including stddef.h, which

What's the use of casting NULL to SomeType* in C++?

点点圈 提交于 2020-03-24 00:09:47
问题 I'm currently grinding through some third-party C++ code that looks rather odd to me (I started out with C++11). One of the many things that left me puzzled, are the many instances of static_cast from NULL to some pointer type: SomeClass* someClassPtr = static_cast<SomeClass*>(NULL); I know you can cast pointers e.g. from a base class pointer into a derived class pointer, but there is absolutely no inheritance going on here. As far as I can see, this should be enough: SomeClass* someClassPtr

Why is the dynamic_cast allowed to yield a null-pointer for polymorphic classes when the destination pointer is not of the type of a base class?

陌路散爱 提交于 2020-01-24 09:00:11
问题 Consider the following program #include <iostream> #include <iomanip> struct A { }; struct C { }; int main() { C *pc = nullptr; A *pa1 = dynamic_cast<A *>( pc ); std::cout << "pa1 == nullptr is " << std::boolalpha << ( pa1 == nullptr ) << '\n'; A *pa2 = pc; std::cout << "pa2 == nullptr is " << std::boolalpha << ( pa2 == nullptr ) << '\n'; } For the both pointer declarations, pa1 and pa2, the compiler reports an error that such an initialization is not allowed. For example the clang HEAD 10.0

With std::optional standardizing, can we stop using nullptr in new code and deprecate it? [closed]

两盒软妹~` 提交于 2020-01-07 05:46:06
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . From time immemorial, when passing pointers to or from functions, we tend to special-case the null pointer: p = get_pointer_to_the_foo(args); if (p == nullptr) { /* foo is inaccessible, do one thing */ } else { /* we can access foo, do something else */ } and this is an

C++11: How to initialize array of pointers of some class with nullptr?

不问归期 提交于 2020-01-06 20:04:00
问题 I am new to C++. I have class named MyDate . In addition I have a class named Calendar which has a member type of array of pointers to MyDate objects. How should I declare and initialize members of the array to nullptr in the constructor of Calendar ? 回答1: Smart pointers default-initialize to nullptr : class Calendar { std::array<std::unique_ptr<Date>, 42> m_dates; }; Otherwise, std::array is an aggregate, so an empty braced init list will zero-initialize all scalar fields: class Calendar {

Array of Pointers to an Abstract Class: to nullptr or not to nullptr (C++)

若如初见. 提交于 2020-01-06 04:43:06
问题 I want to loop through an array of pointers to an abstract class to find an "empty" slot, that is to check whether an element points to an object of a derived class or not. My approach is to create the array and set each element to nullptr. Then, I can check if the element is nullptr. This works, but is there a better way? Edit: Can I check for the first "empty" element in the array of pointers to an abstract class (in which derived classes will periodically be constructed and pointed to by