« first day (352 days earlier)      last day (2506 days later) » 
00:00 - 14:0014:00 - 20:00

12:01 AM
@Merle SSCCE please
also: you're aware that using Block::Block brings all the constructor overloads into the derived class scope? how are you creating the object?
 
@milleniumbug just in vector.push_back(new Block(...));
 
...
the derived class constructor is not called because you're not creating instances of the class derived
 
well that was pretty obvious
 
Also use std::unique_ptr and std::make_unique instead of new/delete
 
what's the advantage?
 
12:13 AM
automatically managed memory, exception safety, not being dumb
ask any person who has been fighting memory leaks
also: automagically composes
 
sounds useful, i'll look into it
 
 
8 hours later…
8:01 AM
Good morning! I have a question, my project is pretty much finished, but i know its not verry good in terms of security, it works with parameters, and if the user start messing arround with the parameters to test the viability of the program, it easly crashes, anny one knows good things i can add to make my program more secure? like control the parameters or something?
 
Ven
8:34 AM
I'm not sure what's your question here...
Yes, you need to check all user entry.
 
i alreaddy have if the number of arguments is less then 2 then it gives an error and greater than 4 it also gives an error (the max number of possible argumentes is 4 in my program)
what else can i add?
 
Ven
find what crashes your program, guard against it
 
8:51 AM
how can i test what crashes my program? do you know annything that normally crashes programs so i can test in mine?
 
Ven
You said "it easily crashes". Fix those crashes.
 
ok :p
why do i get this in my code -> "cout" is ambigous
never happened to me before
 
Ven
do you using namespace std;?
 
yes
 
Ven
Very bad idea. If anyone wants to use another name or if C++ adds functions, everything breaks.
don't ever do that
 
9:04 AM
oh i didnt knew that o.o
so i just do std::cout in stead of adding std?
ok i replaced all i use from std with the std:: behind and removed the using namespace std and now no errors :P
thanks !
 
Ven
nice :)
 
9:28 AM
@Ven, how do i see if a string starts with something in c++?
 
Ven
that's an easy google away ;-)
 
oke :v
 
Ven
I recommend using string.compare(0 /* where you start */, other_string, other_string.size())
 
@Ven i saw someone using the boost libraries to compare strings, do you recomend me using thoes libraries?
128
Q: How do I check if a C++ <string> starts with a certain string, and convert a substring to an int?

Daryl SpitzerHow do I do the following (Python pseudocode) in C++? if argv[1].startswith('--foo='): foo_value = int(argv[1][len('--foo='):]) (For example, if argv[1] is '--foo=98', then foo_value is 98.) Update: I'm hesitant to look into Boost, since I'm just looking at making a very small change to a...

the accepted awsner
 
Ven
I think it's overkill, if you include them only for starts_with
 
9:31 AM
what are they for?
i never eard of them
 
Ven
many different things. metaprogramming, async, i/o, filesystem, lambdas, strings, algorithms...
boost is a collection of libraries
 
ohhhh
that seems fun
what is metaprogramming? can u explain or should i just googl eserach?
 
Ven
programs that generate programs
 
oh
 
Ven
templates are one exemple, macros are a (bad) one, etc
 
9:40 AM
str.find_first_of("my string", variable_to_compare);
imma try this
 
Ven
that... doesn't do what you want.
 
10:06 AM
@jeyejow read the description carefully
 
@milleniumbug ohh
@Ven i have a problem with what u sed, what am i doing wrong?
(std::string)argv[i+1].compare(0, "/", 1);
 
Ven
aaaaaaaaaaa
 
argv is a char *
it gives me the error "expression must have a class type"
in argv[i+1]
 
Ven
yes
you want std::string(argv[i+1]).
 
ohhh ok ill try that
now it gives me annother error in the .
 
Ven
10:16 AM
`(std::string)abc.def()`:
- a cast is most often a bad idea. a C cast (that is, `(type)var`) is ALWAYS a bad idea.
- writing `(type)a.b()` applies the cast to `a.b()`, not `a`
 
lol don't use C style casts
May 5 at 11:55, by milleniumbug
pass -Werror=old-style-cast and remove as soon as one appears
 
Hey
I'm making map function that returns map, but I cant get it to work..

h.
map generateMyMap(vector<string>names)

I get
error: invalid use of template-name 'std::map' without an argument list
map generateMyMap(vector<string> names);
 
so doing this (std::string)variable is bad and doing this std::string(variable) is good?
 
Ven
@Dariusz you need to pass the types to map.
also, use unordered_map
 
@Dariusz std::map is a class template just like std::vector is
 
10:19 AM
@ven you mean map<string> generateMyMap ?
 
do you know what a map is
 
Ven
@Dariusz a map takes two parameters.
the key and the value.
 
I started using it yesterday so as far as I kniow its dictionary
so map<string,string> generateMyMap
 
Ven
yup
 
mm
thank you!
yay it compiles, thank you!
 
10:21 AM
@jeyejow yes, the latter does what you want
 
i see
well, i still get a error, can someone tell me what im doing wrong?
if (std::string(argv[i + 1]).compare(0, "/", 1))
{
std::cout << "it starts with a '/' !";
}
i get a big error in the if, were the . is
std::string(argv[i + 1]).compare(0, "/", 1)
 
post the error message
 
ok
 
if it doesn't fit in the message box, put it on pastebin
 
1 sec
^ there is the error
it makes no sence because im using a int, a const char and a in
i dont know :v
 
Ven
10:27 AM
oh, you want to compare a single char?
 
oh, right, there's no overload with these parameters en.cppreference.com/w/cpp/string/basic_string/compare in there
 
i have a argument in argv[i] and i want to see if the argument in i+1 starts with a /
 
IOW your argument order is different than it should be
std::string(argv[i + 1]).compare(0, 1, "/") == 0
also you should be comparing with 0 because .compare returns 0 when they're equal
 
ohhh i see, ill try that
 
I have
vector<map> *myItems;
map<string,string> *itemString
map<int,int> *itemInt
myItems = {itemString,itemInt}

is there a way to get something like this to work in C++ or I can have only 1 type of item in vector?
 
10:31 AM
why are these pointers
 
yey no error, ty
 
coz they would be QWidgets, so for now I just put string
but they would point to QT widget
 
that's irrelevant
 
I want to have 1 array/container that holds all my widgets references
 
if you're storing Qt objects, you'll store a map of pointers, not a pointer to map
 
10:33 AM
yep
well its osmething like
map<string,QLineEdit*> *lineEdits;
 
map<string,QPushButton*> *pushButtons;
 
map<string,QLineEdit*> lineEdits;
 
oh
ee
ye
 
don't make a pointer to map, that's silly
 
10:34 AM
sorry my bad!
 
also don't use pointers in general, Qt uses them, but Qt is from different times where they have been used all the time, so rewriting the lib so it wouldn't use them would break so many existing programs
 
should i make a function to do something i otherwise need to copy pasta like 5 times in my code, or it isnt needed for that small amount?
 
what should I use instead of pointer? - sorry new to C
 
i like pointers but i dont really understand them, i know that & points to the memory, and -> points to something and * points to another something
 
but yeah if I have
map<string,QLineEdit*> lineEdits;
map<string,QPushButton*> buttons;
how can I now put them in vector?
is it like this >
vector<map*> myVec = {lineEdits,buttons}
@jeyejow I though that *this pointed to memory and & well this is still magical to me...
 
10:37 AM
@Dariusz as far as Qt goes, go along with their convention (IOW the root object owns the children), and ideally this should be the only place you're using raw pointers
 
oh i dont know,i never learned how to mess with vectores, im still learning
& give you the memory name or whatever it is called, if you do int i = 5 and the std::cout << &i , it will give you the name of the place in RAM or something like that,
 
uu nice thanks!
 
atleast thats what i think it does
 
that's a fairly bad explanation :(
@Dariusz a vector and map stores values of only one type, but:
 
@milleniumbug don't think I'm advanced enough to understand what you mean :- ( I though that by storing widgets I want in array I can them loop over it and get a .text() data or something like that...
 
10:39 AM
xD its hard to explain something i dont really understand, maybe i should just stay quiete xD
 
QLineEdit and QPushButton have a common ancestor
 
its ok I understand :- ) I know vector can store only 1 type of "stuff" I just wondered if there is some magical stuff that allow for different stuffs to be storred in 1 spot
 
so you can make these std::map<std::string, QWidget*>s instead and you'll be able to store both of them in a single std::vector<std::map<std::string, QWidget*>>
 
like
for item in vector:
if item.type == map<string,QLineEdit>
do stuff
if item.type == map<string,QCheckBox>
do stuff

etc etc - in my broken pythonic way
uuuuuuuuuuuuuuuuuuuuu
QWidget interesting thanks!
 
Ven
you should try to write C++ instead
 
10:41 AM
no idea how to do it in C yet :- )
 
Ven
not C, C++ ;)
 
isnt C = C++?
 
just showing why I wanted to have 2 differnet map in 1 vector
 
@jeyejow yes, it isn't
 
ahahahahha
ok ok :p
 
10:42 AM
C is older&more advanced I think/ but C++ is almost as fast as C so ehh no idea
 
but they are related, no?
i mean they start with the same letter
 
hahahaha yeah I think C++ is child of C
but what Do I know
 
Ven
idiotic and incredible both start with the same letter
 
people told me C++ was a poorly made language
 
at least its C++ and C and not C and c :p
 
10:44 AM
and thats why C# will take over
 
they are related as in C++ was based on C, they are not related as in there are C programs whicl will not compile with a C++ compiler
 
isnt there C, C#, C++ ?
 
C# is fairly unrelated
 
c# is made by microsoft
and it needs .net to run
 
also using C style programming in C++ will annoy many C++ programmers, and vice versa
 
10:46 AM
is C thats diferent from c++?
 
Ven
yeah
 
i dont know, i use C functions but i never worked with C
ohhh
 
I'm staying away from C# I bet MS will implement some usage statistics/tracking etc in to compiler so that any program made in C# automatically send shit to MS : p MS is evli @_@
 
damn my problem is so big, how do i split my program into files?
its getting hard navigation thro it
 
10:48 AM
wow
 
hahahha @Dariusz
 
so funny. I have my program in separate h/cpp files and yesterday I discovered I can have 2 classes + in 1 cpp/h file. You are inverted u have all in 1 file lol :D
 
well they alreaddy do that normally, if you install windows10 and do a personalized install, you will see alot of things marked to send info to them
xD
 
yep I know, but they don't do that yet(at least I think) on compile side. So your program compield by MS does not send stuff to MS, but it probably will. Total data domination lol
ok enuf of conspirycy shit back to coding and crashing lol thanks for help !
 
xD
 
 
2 hours later…
12:36 PM
i have a problem, i need some help
in my program i take arguments, and i have a for cicle to go trho the arguments the user inputed and the argument next to a, for example a /i will be store in a variable
for example: program.exe /i hello
in my for cicly will be: variable = argv[i+1];
and that works fine, but it the user only inputs program.exe /i , my program will crash because it tries to get the next value to /i and finds nothing
what can i do for it not to crash?
 
don't try to access argv[i+1] if i+1 is more or equal to argc
 
ohhhhhhhh i see
ill try that, manny thanks
 
12:54 PM
if i convert a char* to a std::string, can i then add "\\.\" to the end of it?
or is there a way to add "\\.\" to it without converting to string?
not the end, the beginning*
 
don't use a char*s
 
but i need to, its a argument
 
no you don't
 
int main(int argc, char* argv[])
 
int main(int argc, char** argv) { std::vector<std::string> args(argv+1, argv+argc); /* use args */ }
 
12:57 PM
can you explain that to me please? i never worked with vectors
what is char**
 
int main(int argc, char* argv[]) is the same as int main(int argc, char** argv) except the latter doesn't lie about what it is
 
lie? what do you mean? char * is the same as char **?
whats is *?
 
79
A: How do I use arrays in C++?

fredoverflowAssignment For no particular reason, arrays cannot be assigned to one another. Use std::copy instead: #include <algorithm> // ... int a[8] = {2, 3, 5, 7, 11, 13, 17, 19}; int b[8]; std::copy(a + 0, a + 8, b); This is more flexible than what true array assignment could provide because it is ...

 
* means pointer to, char* means pointer to char, char** means a pointer to a pointer to char
 
^ see the "Parameter passing" section
 
1:00 PM
what do we use pointer to a pointer?
this is kinda confusin :O
does someone have a link thats explains pointers??
 
you use it to throw it in the trash and use an actual array of strings instead of its emulation
 
in this cast argv is a pointer to a array of pointers each of which point to null terminated strings
 
a pointer to an array of pointers that point to x null terminated strings
what
how can one thing point to an array of pointers
this is so confusing for me
i get the pointer (kinda) but a pointer to a pointer thats is pointing to something
why all that
 
@milleniumbug it'd be nice if array_view and string_views could be used to avoid allocations there
 
1:06 PM
so if i say char** argv[0], i am pointing my char** to the char*[0] ?
 
o.o
 
char** argv[0]; is invalid declaration because zero-element arrays are illegal
 
argv[0]'s type is a char*
indexing into a pointer removes a level of pointerness from the type
 
but i dont understand, if i declare char** argv, what am i declaring?
 
1:08 PM
char** argv; declares a argv variable of type char**
 
:V
 
and char** is a pointer to char*
 
but were is it pointing
 
@jeyejow if it's not initialized, nowhere
 
if it's a parameter, to wherever argument someone passed
 
1:09 PM
so char** argv is point to a char*, and a char* is pointing to a char, so char** is point to a char?
 
char** is just like T* where T is char*
 
if i have this char** ex[5], do i have 5 char*[5] ?
 
@jeyejow argv[0] is not the same as argv[0][0]
 
@ratchetfreak thats is bidimentional
 
@jeyejow no
also read that entire question in its entirety
 
1:12 PM
ohhh so cahr** is like a bidimentional?
 
386
Q: How do I use arrays in C++?

fredoverflowC++ inherited arrays from C where they are used virtually everywhere. C++ provides abstractions that are easier to use and less error-prone (std::vector<T> since C++98 and std::array<T, n> since C++11), so the need for arrays does not arise quite as often as it does in C. However, when you read l...

 
ohhh i kinda get it
 
pointers are addresses of values, an address is also a value so you can have the address of an address
 
so i dont need to have an array to make a point
pointer*
if i have like int(*)[8]
it will create a array with 8
 
int (*x)[8] is a pointer to int[8]
 
1:21 PM
why the x?
 
it's a name of the variable you're declaring
 
is it the variable?
ohhh
so if i do x[1] = 'e'
but i dont get it, whats the point of using pointers if i can just creat an array?
 
because array has a size known at compile time
also for the nth time: std::vector and std::string
 
so with pointers i can do something like this? int* d[f];
f = users input
?
 
1:25 PM
well then
 
that is, yes, but not with that syntax
 
ok, i kinda get pointers
but pointers to pointers make me confuse
 
int* is T* where T is int. char** is T* where T is char*
 
so a pointer is like a normal variable, from what i understand
so int t is the same as int* t ?
 
@jeyejow no
 
1:27 PM
well then
 
lolno
 
int t is a number
int* t is a ?
pointer to a number?
 
pointer to int
 
but what is the diference
both store numbers
 
jsdfjongfouisdfhnvgkjfsdngskfjdxfsgjn
no they don't
 
1:28 PM
sorry, it even annyois me that im dumb like this xD
what do they store then
 
that you need to dereference the pointer to get to the number that is stored elsewhere
 
let's go with basics
let's say you have a type T
 
ok
type T
 
and you declared a variable of that type
 
ok
 
1:29 PM
T a;
 
hm
 
then you declared a pointer
T* p;
 
ok
 
I can make that pointer point to that variable
p = &a;
 
ohh
 
1:30 PM
and now that I have a pointer p that points to a, I can do this
 
so if i do p = 5 then the value of a changes to 5?
 
*p = some_value_of_type_T;
 
@jeyejow no that's a compile error
 
ok ok, i think i get it
 
and a is modified
 
1:31 PM
you need to dereference the pointer to access what it points to
 
@ratchetfreak awsdaws u get what i was trying to say xD
 
* and & are operators, and they are inverses of each other
 
nice i think i got it now
my only question is
if i have a type T
and i do this
 
now, T can be an int, char, or long*
IOW T can be also be a pointer
 
T* x[];
and i then i do this
*x[1] = 5 ; (image that x has like 5 length)
whats am i doing?
x is a pointer, so why can it hold things?
were is x pointing to?
 
1:34 PM
T* x[]; is not legal declaration of a variable
T* x[5]; does compile
 
then why can i declare char* argv[] in int mein?
 
because in parameters, argv is not actually of type char*[]
79
A: How do I use arrays in C++?

fredoverflowAssignment For no particular reason, arrays cannot be assigned to one another. Use std::copy instead: #include <algorithm> // ... int a[8] = {2, 3, 5, 7, 11, 13, 17, 19}; int b[8]; std::copy(a + 0, a + 8, b); This is more flexible than what true array assignment could provide because it is ...

^ see this
 
ok, so if T* x[5] compiles, and i do *x[5] = 'e', why can it hold 'e' and were is *x[] pointing to?
ok :v
 
better yet, read all of the answers in that question
it actually explains this better than I could ever hope to
 
hmmm so int *p[something] points to imaginary place
i see
 
1:39 PM
what
 
+---+---+---+---+---+---+---+---+
(anonymous) | | | | | | | | |
+---+---+---+---+---+---+---+---+
^
|
|
+-|-+
p: | | | int*
+---+
oops that was a bad copypasta
 
there is a fixed font button to fix that
 
how
were
 
go to edit the post (press up a few times) and it will appear
 
1:40 PM
             +---+---+---+---+---+---+---+---+
(anonymous)  |   |   |   |   |   |   |   |   |
             +---+---+---+---+---+---+---+---+
               ^
               |
               |
             +-|-+
          p: | | |                               int*
             +---+
oops missclicked
but nice
i didnt knew that :O
Obviously, anonymous arrays require more memory than named arrays due to the extra pointer that must be stored separately. (There is also some additional overhead on the free store.)

Note that there is no array-to-pointer decay going on here. Although evaluating new int[size] does in fact create an array of integers, the result of the expression new int[size] is already a pointer to a single integer (the first element), not an array of integers or a pointer to an array of integers of unknown size. That would be impossible, because the static type system requires array sizes to be compile-t
isnt that what they mean?
that int* p[something] is like imaginary memory?
 
yeah no
 
there is no imaginary memory
 
00:00 - 14:0014:00 - 20:00

« first day (352 days earlier)      last day (2506 days later) »