« first day (260 days earlier)      last day (2589 days later) » 

8:48 AM
hello
I was reading through this question stackoverflow.com/questions/10802046/…
but I don't understand what is std::unique_ptr
can anyone explain to me in a nutshell what it is?
 
nwp
A pointer that owns the object pointed to. When the unique_ptr disappears it takes the object with it.
 
so this avoids memory leaks?
 
yeah it uses RAII semantics to ensure that delete gets called when it goes out of scope
 
is it like java then? like a kind of garbage collector?
and is it then "risk free"?
like all the problems I could have with new and delete
are all
avoided
using std::unique_ptr
?
 
not all but most will be avoidable
 
8:55 AM
which ones would remain?
 
when multiple objects want to share ownership
when objects own each other in a cycle
 
what do you mean by "ownership"?
 
nwp
@user8469759 yes, you are not supposed to use new unless you write a smart pointer or container
 
but in practice... say I would do something like
Type x = new Type;
do_something(x);
delete x;
using the std::unique_ptr
does this mean that snippet would be substituted with
 
nwp
@user8469759 don't do that, the correct way is Type x; do_something(x);
 
8:59 AM
std::unique_ptr<Type> x(new Type);
do_something(x);
?
I'm not sure how to use it
 
 auto x = std::make_unique<Type>();
 
auto means the type is inferred, right?
so it infers Type from the call to std::make_unique<Type>
 
nwp
yeah, you are supposed to know that make_unique returns a unique_ptr
 
what about casting instead and inheritance
 
nwp
make_unique is just a function that returns a unique_ptr
 
9:01 AM
does this stuff behave well with virtual methods, destructor etc?
 
nwp
@user8469759 to be avoided like the plague, but properly supported by unique_ptr
 
I'm not sure I was clear
 
it'll work but there are other reasons you shouldn't use inheritance
 
say I have class Base and class Derived, class Base has a virtual method f(), declared in Base and implemented in Derived, can instantiate a type to derived using std::unique_ptr but using a ptr to Base to manipulate the objecT?
why is that? I've seen bunch of frameworks and in general a lot of code that make use of it
 
OOP is highly overrated
 
nwp
9:05 AM
@user8469759 you can do std::unique_ptr<Base> up = std::make_unique<Derived>(); up->f(); and it will work just like with regular pointers
@ratchetfreak I disagree. OOP is the best thing ever and inheritance is bad for OOP.
 
I disagree with you both xD
 
nwp
but that is just because the understanding of what OOP is greatly varies, so one would have to define the term properly first
 
OOP as they teach in programming courses
 
anyway ok
 
9:29 AM
Nuke "OOP" from orbit
 
 
5 hours later…
2:05 PM
hello
is it possible to add the libraries to an excutable?
because i want to run compiled program in another machine
now i need to download all the libs i've used
 
nwp
the magic words are "static linking vs dynamic linking"
 
nwp
in theory it is possible and easy, in practice it is a huge pain to go through compiler options and get the legal right to do what you want
 
i use cmake
 
nwp
good luck
 
2:09 PM
most people use an installer that will copy the dynamic libs next to the executable
 
nwp
it's most likely way more annoying to get cmake to produce a statically linked executable than to copy the dll's to the target machine
 
im on linux
 
nwp
but maybe the libraries you have are well behaved and already have that option
 
how i can automatically copy these libs next to the excutable?
or i can't?
 
nwp
Put them in a zip file? Some time ago there were programs that would take an executable and a bunch of libs and produce a new executable that embeds everything and unpacks the libs at runtime and starts the original executable without the user noticing.
 
2:13 PM
that was nice
so... if i have dynamic libs i need to copy them next to excutable?
 
nwp
What libs are we talking about? If they are available in your package manager the correct solution is to make a package that has those libs as a dependency.
 
shared libs
 
nwp
which you built yourself?
 
nwp
in that case you could just stuff the code into the main program and not make a lib
 
2:18 PM
i just built the lib by myself (i don't own it)
 
nwp
So we are talking about OpenSSL and zlib? In that case don't distribute them with your program, list them as a dependency in a package instead.
 
ok, what about the shared lib uWS?
also my program uses box2d (it's shared lib too)
so... should i install all the dependencies manually? i'm a bit confused right now
 
nwp
you should have a package manager like apt/dpkg or npm or ... whatever they are called
that package manager is responsible for finding the libraries your program needs, that's not your problem
what you need to do is stuff your program in a package that has the required other libs as dependencies
At least that's the Right Way to do thing. The Bad Easy Way is to just put everything in a zip file.
 
along with a README that tells the user to install certain packages
 
ok
i'll compile each these libs, it will take 10 mins for me
ty for information
 
 
4 hours later…
6:35 PM
hello
@ell
:)
I have a vector like this: vector<uchar> info
From which I'd like to print the content.
When I do: cerr<<info[i]<<endl;
I get weird characters
 
Ell
uchar being unsigned char?
 
yep
 
Ell
and you want to print them as decimals or the ascii characters?
 
hmmm my guess after reading the docs is that decimals might be the best.
 
Ell
in that case
you could use a stream manipulator
 
6:38 PM
nothing overly complicated would be nice
 
Ell
sure, gimme a sec
 
ok
 
Ell
hmm it seems manipulators don't do that
 
ok solved
 
Ell
you can just do static_cast<unsigned>(info[i])
 
6:40 PM
just had to add int(info.[i])
:)
 
Ell
@trilolil don't use int()
as in, don't use c-style casts
 
no?
 
Ell
use static_cast<int>(...)
@trilolil it's bad practise in c++ to use that style of cast
 
yhea I'm a C-guy
 
Ell
and bad style :)
 
6:41 PM
OK thanks :)
 
7:28 PM
int() is not a C-style cast. (int) is.
 
nwp
@Brandin it doesn't compile in C, but it does what a C-cast does, so arguably it still counts
 
 
1 hour later…
8:32 PM
Why do game designers seem to like Lua for game scripting?
 
nwp
because it is a good option to make a game moddable in a way that it is possible to make anything in the game because it is a full featured programming language while at the same time preventing people from making mods that format your harddrive
 
8:58 PM
@Brandin because it's simple enough they can read the code, it's small, and easier to embed and sandbox, than, for example, JS or Python
 

« first day (260 days earlier)      last day (2589 days later) »