« first day (1416 days earlier)      last day (1653 days later) » 

13:30
LRUCache(size_t capacity):m_capacity(capacity) {
}
I get that this is the constructor but how does the :m_capacity(capacity) bit work? what is it called?
@Permian confusingly it's the initializer list
which is not directly related to std::initializer_list
omg lol
all i can see there is that the capacity attribute is set
(size_t one)
@PeterT ill take a look. i looked at the tutorials (easier to read) but they had the same knowledge level i had
@PeterT this is so hard!!
sorry ive read that a couple of times but I still dont get it for my example
LRUCache(size_t capacity):m_capacity(capacity) { }
why do we need size_t capacity in the brackets if we call capacity from the initializer list?
13:48
that's just the input parameter, it's something like this
LRUCache(size_t capacity) { m_capacity=capacity; }
why not just do LRUCache() { m_capacity=capacity; }
but it doesn't need to default initialize m_capacity before entering the constructor
nwp
nwp
@Permian What is capacity here?
the capacity of the LRU cache
how many key value pairs it can hold
he's asking how the compiler would find it if you didn't pass it as a parameter
nwp
nwp
13:50
If that is a global variable you can do that and it essentially does the same thing as the initializer list version.
jrh
jrh
To answer my own question from earlier, What are copy elision and return value optimization?, "If a call to a copy or move constructor is elided, that constructor must still exist and must be accessible. This ensures that copy elision does not allow copying objects which are not normally copyable, e.g. because they have a private or deleted copy/move constructor."
@PeterT no it looks like from the cpp reference that once you have an initializer list this takes over the initalization of the attributes
nwp
nwp
The reason why the initializer list exists is for cases like struct S{ S(int i){} }; which means you require an int to construct an S. If you have a struct A { S s; A() {} }; then that doesn't compile because A::S requires an int to construct and you didn't give it one.
also for initializing references and stuff like that
not that you should make a habit out of having data members that are references
nwp
nwp
You can't do A() { s = 42; } either because first the s was already constructed when the { is reached and you need to initialize with 42, not assign it. So you need to initialize s before you reach the constructor body.
The way to do it is A() : s(42) {}.
Sometimes you must use the initializer list, sometimes you can simply assign. For consistency people tend to always use the initializer list even if it's not strictly necessary. You eventually get used to the quirky syntax.
user11702787
14:09
is there a way to "translate" C++ Code into Python if you dont know C++ ? or just learn the basic structure ?
nwp
nwp
If you "translate" C++ code to Python code you get C++ code with Python syntax. It's not very useful. Depending on what you want to achieve there is probably a better way.
Do you want to port a program from C++ to Python or learn C++ or something else?
 
1 hour later…
15:24
Trie* next[26] = {};
Trie is a defined class
what is this initialization called?
couldnt find that thanks
it's not like C++ makes it easy :P
@PeterT i think you are missing a word
yes I accidentally a word there, hehe
15:27
c++ is just so huge
@PeterT i see a lot of guys doing this sort of thing
unordered_map<int, list<int>::iterator> pos;
list<int>::iterator why do this and not just a reference/pointer to the list?
maybe they use it later on to insert something after it
or to increase the iterator
or to remove it from the list
yeah they're calling erase for example
how does the ::iterator work better than a reference?
how would you remove an element if you have the reference without iterating over the list again?
15:43
not sure what you mean
you have a list, you a reference to an element in the list, remove the element without searching for the right one
oh ok
@PeterT so these iterators basically have a list of pointers to items to within, say, a vector?
how an iterator works depends on the container
vector then
for a vector a T* is a good enough type for a vector
15:57
why
and its not for a list because?
because a list has different iterator invalidation rules and doesn't store elements contiguous in memory
where can i find about this myself?
I guess googling iterator invalidation rules and iterator requirements
ok thanks
16:15
does the begin() in c++ point to the first element in the vector or the space before the first element?
derefrencing it gets you the first element
because apparently end() points after the last element
yeah, it's pretty much always the same, because end() is like a sentinel value for "not valid", because the functions like find need to return something that signals "nothing found"
yeah
so begin is the first element
and end if after the last element
The one before begin() would be rend() in the case of vector
16:18
ok
but i == 0:
i = insert(i, 5)
inserts a 5 at the start of the vector
you mean "auto i = vec.begin();" ?
sorry i saw it and cant find it now
16:52
Would there be any reason that my login fails on apache?
a lot of them
Like?
The ajax and php (off topic for this room, sorry) have worked for years. It's simply my machine
did you even find the right config, last time you wrote that changing the port in the config didn't work
Yes
I'm not really sure
then find the right config :P look in /etc/apache2 or somewhere
if you've fixed the paths the next thing I guess is to make sure that the HTTP method is whitelisted/allowed
the login might be done via POST unlike the normal pages GET
16:57
Oh whitelisted?
Hmph okay
I don't know the default, but I remember it having a "nooveride" thing or so in there, so if you have .htaccess overrides they might not be active
Or a content-type whitelist if it's a POST request, there's so many headers that could make trouble
Ah okay
@PeterT ive finished my iterators reading now
great stuff, looks like a powerful feature for abstraction
its a shame that they put STL in standard C++ textbooks
iterators are sort of alright, they're not ideal or we wouldn't need ranges in the new standards if they solved all problems
what are the new standards trying to solve?
17:08
better representation of ranges without two iterators or a pair<iterator,iterator>, representing generator-like iterators better and not being so very verbose
17:43
Hi guys, Im a newbie with c++ and am having a problem.
I have an int in my header file under private and that variable is accessed in another file and is changed. I'm trying to call that same variable to the main function, but it isnt working
@user2277747 got some code? hard to understand from the description
@PeterT, yeah, I posted about it here: stackoverflow.com/questions/62048958/…
you call int count = guess.getSum(); before sum has its final value
call it after the while loop
after the while loop but before the .beginGuessingGame function?
nah, I though after, but it seems like beginGuessingGame is an endless-loop
when should it stop?
17:49
when the user has guessed the integers correctly
sum will be equal to the number of integers the user wants to guess
you don't check anywhere if all the guesses were correct
beginGuessingGame just never returns
isn't it checked in the main function?
how do you think you're getting out of the for (;;) {?
oh
But doesn't get out of the loop is sum changes
if*
no, if you mean the "break" that only gets you out the inner most loop
17:56
How would i exit this loop if I want the user to guess as much as they want
make the user input a special value or string to signal a stop value
How is sum changing if the loop never exits to the next one?
I don't understand the question
If the program never exits for(;;), how is sum changing in the other loop
you do change sum to 0 and then counting up, what does that have to do with getting out of the for(;;) ?
18:03
oh, do both loops execute simultaneously?
I just think the "for (;;) {" is a mistake
you already have the while loop in main
 
1 hour later…
19:13
while (true) gang vs for (;;) gang?
20:02
Hello people! I've a little code snippet. It'd be great if you could help.
class car
{
public:
    int a;
    float b;
    car(){}
    car(int m, int n)
    {
        a=m; b=n;
        disp();
    }

    void disp()
    {cout<<a<<endl<<b<<endl;}
};

class lambo: public car
{   public:
    void disp()
    {
        car(2,5);
        //car::disp();
    }
};
int main()
{
    lambo l1;
    l1.disp();
}
class lambo: public car
{ public:
lambo(): car(2,5) {}
};
the commented line resets the vales of car::a and car::b to 0. Everything else looks good
there's no resetting, you never changed the values in lambo itself
@PeterT hi peter
you just created a temporary instance with the correct values
20:07
@PeterT okay, so previously car::disp() printed 2 and 5. Why is the value changed to 0 next?
it's not changed, you're printing the values of another instance
@PeterT didn't get you :(
@PeterT okay... the temp instance you talked about?
car::disp() will call disp on "this"
@PeterT okay,
@PeterT could you please tell me why is the temporary created,
it's the same as if you would do something like int(5);
so it's like "car mycar(2,5); " but because it has no name it just gets destroyed immediately
20:15
@PeterT okay, just after disp( ) runs, the object is deleted... is it?
it's deleted after the statement is executed, the only thing the statement does is run the constructor. So yes, since the last thing the constructor does is call disp, after that it gets destroyed.
Hey guys, anyone here? Do you have a great solution to detect memory leaks in VS 2017?
@Tivi the heap snapshots are nice
just make multiple snapshots and compare them to see where memory is allocated
@PeterT hi, I'm sorry but I'm still a bit confused, aren't we using l1 as an object of the lambo class and all the members of this class are used...
@PeterT Thanks! Is there any guide online how to do that?
20:28
@user8718165 yes, but you never change the a and b from l1
@PeterT Aha... so when we passed 2 and 5 we didn't send it to l1.a and l1.b respectively?
yes, that was the a and b of another instance of car
Instead we created a temp object of type car and sent it there?
yes
@PeterT Yeah. I got it :)
@PeterT Thank you so much for your time and assistance. See you n be safe.
20:33
@PeterT Thank you so much - I'm gonna check it out now!
21:15
688
A: "static const" vs "#define" vs "enum"

Jonathan LefflerIt depends on what you need the value for. You (and everyone else so far) omitted the third alternative: static const int var = 5; #define var 5 enum { var = 5 }; Ignoring issues about the choice of name, then: If you need to pass a pointer around, you must use (1). Since (2) is apparently...

> (1) cannot be used as a dimension for arrays at global scope; both (2) and (3) can.
Why is it so?

« first day (1416 days earlier)      last day (1653 days later) »