Liam
What about this ?
https://en.cppreference.com/w/cpp/language/overload_resolution
Anonymous
Liam
Just read the link above.
Liam
Everything related is listed there.
Emir
no
Can u explain that code
#include <iostream>
#include <stdlib.h>
void a(void * ptr) { std::cout << "1" << std::endl; }
void a(int ptr) { std::cout << "2" << std::endl; }
void a(char * ptr) { std::cout << "3" << std::endl; }
void a(long ptr) { std::cout << "4" << std::endl; }
int main() {
a(NULL);
}
Kobbina
Please I need help
Emir
Emir
NULL makro is (on mac os) (long)__NULL
Sinan
So why that code prints 4 ?
Sinan
Oh okay
Serhii
Emir
Emir
4
Program ended with exit code: 0
Anonymous
on my Linux it's just __null
Anonymous
So why that code prints 4 ?
gathering everything here
for libstdc++
NULL is defined as __null
__null is an integer with size same as void *. void * on your system has the same size as long.
so NULL is a long
so the fourth overload is picked because no conversion is involved
Liam
This kind of stuffs is boring...
Avoiding using NULL in modern C++ terminates the discussion.
Sinan
Serhii
No, 4
depends on you system. NULL may be defined as
#define NULL nullptr
and though it can result in compilation error
Emir
Liam
Emir
in mac os it’s not like this /:
Kobbina
Emir
#define NULL _null
#define __null (long)__null
Liam
Kobbina
Liam
#include <cstddef>
#include <type_traits>
#include <iostream>
class S;
int main()
{
int* p = NULL;
int* p2 = static_cast<std::nullptr_t>(NULL);
void(*f)(int) = NULL;
int S::*mp = NULL;
void(S::*mfp)(int) = NULL;
if (std::is_same_v<decltype(NULL), std::nullptr_t>) {
std::cout << "NULL implemented with type std::nullptr_t\n";
} else {
std::cout << "NULL implemented using an integral type\n";
}
}
This helps testing the definition type of your arch.
Anonymous
Anonymous
that's why i said libstdc++ when describing my system
Emir
Anonymous
New here
Anonymous
i have two functions
template<bool mutability>
class _iterator_templ {
template<bool B, typename std::enable_if<B, bool>::type = true>
_iterator_templ &operator=(const _iterator_templ<B> &other);
_iterator_templ &operator=(const _iterator_templ &other);
}
but if i do
_iterator_templ<true> i, j;
i = j;
the program compiles fine (and the assignment uses the nontemplate member). shouldn't there be ambiguity since both functions are available for use
Francisco
Hermann
mpz_export convert mpz to my data? i dont undestand it
Hermann
?
Francisco
Anonymous
oh
Patrick
Hi, I'm new to std::shared_ptr and I'm wondering how to assign one into a std::variant?
I'm getting this error:
no matching function for call to ‘std::shared_ptr<Cell>::shared_ptr(std::shared_ptr<Cell> (*&)())’
I think I'll have to provide more code as an example.
Patrick
https://repl.it/repls/SizzlingEverlastingDriver#main.cpp
Here's the non-working code in a repl.it
Patrick
Thank you very much! I'll need to be careful about including the constructor. Out of curiosity what use does not including a constructor have?
Patrick
Ahhhh, got it. I'll keep that in mind for when I start getting more functional with C++ :)
Anonymous
How much work experience you have
Anonymous
?
Anonymous
Anonymous
Because of your knowledge
Anonymous
Can i ask something
Anonymous
Yep it is related to cpp
Anonymous
How many languages you know other than cpp
Anonymous
And how you learned these many things
Asdew
11111 members!
Anonymous
Asdew
Asdew
Oh.
Asdew
Well, we still just did have that amount.
Anonymous
What is your job actually?
Anonymous
What you do
Anonymous
Mar!o
Reference counted smart pointer
Anonymous
Anonymous
What it is used for
Mar!o
Prevent memory leak. It frees the memory when the reference count is 0 and no object longer refers to it. std::weak_ptr is the counterpart to access the memory without changing the reference count. To use the memory you have to call lock which converts it to a shared ptr
Anonymous
What is copy elision?
Anonymous
Anonymous
Thanks for the warm welcome
Anonymous
i never saw usage of "using namespace std" back in 2014 but now . they are used in almost all the programs
Dima
Anonymous
Dima
I won’t explain shit
Anonymous
i think maybe they are advanced programs
𝑨𝒋𝒊𝒏𝒌𝒚𝒂
What is used of this pointer in c++?
Marku
Hello Group !
Marku
i have a doubt, why when i declare an array or even a variable, there are some values? if i never before assigned that array or variable ? in the image i show better what i am talking about
Marku
Anonymous
You shouldn't use uninitialized variables, array, etc
There may be some values.
Marku
for example, int convertedNumber[64] is an array recently declared and never assigned before, and it's the first time i run this code, but look there are a lot of values
Anonymous
Using uninitialized memory is undefined behavior => it can lead to any consequences
Marku
Marku
ok i will verify that way, Thanks for help 👍
Marku