« first day (1251 days earlier)      last day (1605 days later) » 

9:02 AM
when compiling a class from the command line, do you compile the .cpp file or .hpp?
 
 
2 hours later…
11:03 AM
res.push_back(nums[i],nums[j],curr_sum - nums[j]);
vector<vector<int>> res;
why doesnt the first line work?
 
@Permian how would it? push_back doesn't take multiple arguments
res.push_back( {nums[i],nums[j],curr_sum - nums[j]} );
might be another topic
 
i thought i tried that
that seems to work
3sum on leetcode is deceptively hard
 
 
1 hour later…
12:27 PM
int l{}, mid{}, h{nums.size() - 1};
what is this notation called?
 
depends on who you ask. "Uniform initialisation" or "brace initialization" are common terms I've seen used
if you mean the initialization with braces, and not the declaring multiple variables in one statement thing
 
12:42 PM
 * Definition for a binary tree node.
     * struct TreeNode {
     *     int val;
     *     TreeNode *left;
     *     TreeNode *right;
     *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
     * };
TreeNode(int x) : val(x), left(NULL), right(NULL) {} why does this do?
@PeterT looks horrendous
 
well member initializer lists were the only option to do this before default member initializers were made part of the language
I still use member initializer lists a lot, I just do it with line-breaks in-between
TreeNode(int x)
: val(x)
, left(NULL)
, right(NULL)
{}
 
1:02 PM
@Permian Lol. Here, it is not brace initilization. It is the constructor's body!
 
@JaideepShekhar woah, you made the actual post on that . Thank you a lot :)
Imma take a look when I find time
 
 
2 hours later…
2:58 PM
@northerner using Cmake for the whole process
 
3:10 PM
I've got something weird going on in my code
switch (a)
case 1: {cout <<"gggg"; return false}
....
so if I comment case 1; it returns true
if I uncomment case 1; it returns false but doesnt output "ggggg"
What is going on here?
the part of the code is written in the bool function
 
@GRRohman maybe the output buffer is just not flushed yet
 
@PeterT I'm not sure what that means exactly.
I'm familiar with output buffer
ok maybe this clears something out
if I remove cout<<"gggg";
and the code remains the same
switch (a)
case 1: {cout << return false}
....
if I comment case 1: returns true
if I uncomment case1: return false
 
I meant you can try to flush the output buffer either with something like
cout << "ggg" << endl;
or
cout << "ggg";
cout.flush();
 
@PeterT didn't help :c
 
3:27 PM
Pretty much every example you posted has some weird syntax errors in it, can you copy the actual code you're using?
 
```
switch (static_cast<int>(pawn.position_1-96)){
case 1: if (take==false && (destination.first>1 || search_Black!=Pawn::positions_Black.end())) return false;
else if (take==true && ((destination.first==1 || destination.first==3) || search_Black==Pawn::positions_Black.end())) return false;

case 2: if (take==false && ((destination.first==1 || destination.first ==2) || search_Black!=Pawn::positions_Black.end())) return false;
else if (take==true && (destination.first==2 || search_Black==Pawn::positions_Black.end())) return false;
``` doesn't work here ?
pawn.position_1 is char
destination is pair<int,int>
take is bool
positions_Black is static vector<pair<int,int> >
search_Black is find(Pawn::positions_Black.begin(),Pawn::positions_Black.end(),destination);
and Pawn is a class
Don't bother for now , I think I found it
@PeterT False alarm, I did not found the (eventual) mistake
static_cast<int>(pawn.position_1-96) is equal to 1
so switch statement should go into case 1
and If I comment cases 2 and 3 it return true
but if I uncomment case 2 and leave the case 3 commented
it returns false
 
I mean do you have warnings turned on? Do you return something in a "default:" or after the switch case?
 
I don't have anything in default , is that necessary ?
After switch case there is only return true at the end of the function
warnings are turned on
 
ok, do you mean to have a fall-through there?
 
where ?
 
3:39 PM
if for case 1 e.g. neither the "if" condition nor the "else if " condition is met?
 
then It should leave the switch case
 
that's not what you wrote in that code
I think you need to increase the warning level of your compiler
 
aha I see
how do I do that ?
im writing in code blocks
Should I tick all the "Warn if ..." in the compiler settings ?
 
well, most of them probably. If one's too annoying you can disable it again
 
@PeterT gotcha , thanks
 
3:41 PM
I think starting with -Wall and -Wpedantic and then dialing back if it's too much works out well
 
So if I understood right
if in my code above, none of the if and else if are met
it goes to case 2 ?
 
yes
 
does that make sense ?
 
what? it's just how that's defined
 
Yeah I understand that's how it is defined, but that doesn't make too much sense to me.
 
3:43 PM
people do some crazy stuff with it like duffs device, but it's an error most of the time, which is why pretty much every compiler has warnings for it
It's just that way because of the simple way it was designed originally as just a list of goto targets
 
aha
ok
 
most people don't expect

switch(x)
{
case 1: if(y){
case 2: }
}

to parse but it does
 
Yeah it makse sense now
Thanks for clarifications
 
well that one doesn't parse, but I mean the cases aren't scoped by default, they're basically just labels
 
Apparently I haven't study switch case before using it
study enough*
Just saw it somewhere and went by the feeling
 
3:49 PM
well, that's usually how I go about things too :P Which is why compiler warnings help
 
Go by the feelings + Bad compiler settings = not good :D
 

« first day (1251 days earlier)      last day (1605 days later) »