« first day (613 days earlier)      last day (2464 days later) » 

Ali
Ali
04:36
I am used to C and Embedded system. For a general C++ developer, myString is a C++ String or C-string. I want to write some code that can be used for learning C++ and I want to make sure I create the correct mind set for a beginner C++ programmer, so he/she can blend better in the future.
 
1 hour later…
05:38
Hi
Anyone there?
I have one small query about c++, Can anyone help, Please?
 
7 hours later…
12:26
I would have tried on SO proper first
Ali
Ali
12:40
I am used to C and Embedded system. For a general C++ developer, myString is a C++ String or C-string. I want to write some code that can be used for learning C++ and I want to make sure I create the correct mind set for a beginner C++ programmer, so he/she can blend better in the future.
teach them the magic of RAII
@Ali go get Bjarne's book
start there work from that
Learn OO, so even if C++ doesn't work out in the future, you might easily convert to a Java or C# developer
can you make it stop fucking raining in C++
if the machine that makes it raining is written in C++, then yes
nwp
nwp
12:50
Clearly C++ is the divine language.
@Ali Maybe look at this.
since you can put C and assembler in c++, I concur
Im still not sure why we have function return values AS well as function output
eg printf can output hello world and return an int, im not quite grasping why there isnt just one or the other
nwp
nwp
Because some stuff should appear on the screen and others should not.
But the idea of a language where every return value is automatically printed amuses me.
but why not just use the return keyword for stuff that doesnt appear
Ali
Ali
@Mgetz Actually that help. Apparently in the guides I checked string is String and C-String is char array.
or the %* format specifier
nwp
nwp
12:59
Because tons of stuff such as i++ has a return value and having to add a keyword to it to stop it from printing is super annoying. Adding a thing to make it print is much more reasonable.
would it make sence to create a static int (for example) inside a class?
printf returns 1 if true but main returns 0 if true
i understand when i do it inside a struct, but im having trouble understanding what a static would mean inside a class
nwp
nwp
You should check the documentation on those return values again. The don't mean "if true".
oh ok thanks
nwp
nwp
13:03
struct and class is the same thing in C++, besides the default access specifier.
Ali
Ali
@CoderCat Actually that is a windows standard to return 0 for successful execution and not the language standard.
oh ok
I know it says 0 if int and 1 if anything else but isnt that implying if int is passed into the function thats true since the definition of printf and main both return an int
class drkk
{
public:

	static int buffering(HANDLE * file, std::vector<BYTE> _data, int point, int pos, int quant);
};

int drkk::buffering(HANDLE * file, std::vector<BYTE> _data, int point, int pos, int quant)
{
	// my code here for the function ...
}
does this make sence?
do i need to initialize de parameters in my class?
and false if non int is passed to the function
13:07
like in here
the example they give they initialize the variables in the class before the public: part
is that needed?
wait i mean this:
static int buffering(HANDLE *,std::vector<BYTE>,int,int,int);
not the thing i have in the class on the code i posted
@jeyejow please don't use that website
24 messages moved from Lounge<C++>
nwp
nwp
Those are the names of the parameters. You can leave them out in the declaration if you want, but usually it makes sense to leave them in. int point, int pos, int quant carries a lot more information than int,int,int.
@jeyejow also this signature is incredibly problematic
@Mgetz oh thanks
13:12
@jeyejow A) HANDLE is already a pointer are you returning it? B) why are you copying the std::vector shouldn't that be const?
what does the int in the return actually convey?
@Mgetz because i need a pointer to a HANDLE
@jeyejow why?
HANDLE is typedeffed as a pointer already
the only reason to ever have a pointer to HANDLE is return one as an out parameter
there are no ownership semantics involved at all
13:14
in general out parameters come last
well i can try just using HANDLE and see if it works
and am i passing the vector wrong?
it should be by const ref: const std::vector<BYTE>&
that avoids the implicit copy that otherwise happens when you pass one by value
why the & in the end?
dont it alreaddy pass the adress normally?
that's the reference marker
when i send vector.data()
13:16
@jeyejow this isn't Java
i never coded in java
C++ has pass by value as the default
this means parameters are copied (using copy constructor) when passed to functions
adding & will instead pass by reference which will not copy the object
yes i know, but arrays when passed they pass the adress and not the values
thats what my teacher told me
arrays are special and annoying in that way
and std::vector is not an array
@jeyejow vector isn't an array, it's an object that holds a dynamically allocated array
13:18
previously i passed vector.data() do a function expecting a vector, and now that it is expecting a const vector&, what do i pass to it?
@jeyejow nice to know teachers are still confusing students
do i still pass vector.data()
@jeyejow just vector
@jeyejow we have no idea what you're doing inside the function.
the function copies 512 blocks of BYTES for the vector i pass it and puts them in a file
512 bytes at a time
13:20
IOW it only reads the data in the vector
then you should pass by const ref
nwp
nwp
Sounds like your teacher thoroughly confused you.
2
yes
to both
if i do this: static int buffering(HANDLE,const std::vector<BYTE>&,int,int,int);
i get and error in my function declaration
this is how my function looks:
int drkk::buffering(HANDLE file, std::vector<BYTE> &_data, int point, int pos, int quant)
nwp
nwp
forgot the const
ah
do i have to make a const vector in int main? or i justmake a normal vector?
and arent parameters constanst alreaddy?
for the function
nwp
nwp
No, you have to explicitly make them const.
13:23
but why does it work if i pass for example a int to a function and i create a array inside the function with the size of that int?
nwp
nwp
Adding const is not a problem because not modifying something you are allowed to modify is ok. Removing const is a problem because modifying something you are not allowed to modify is bad.
@jeyejow Because you are using non-standard extensions.
so if i wanted to modify the vector i just remove the const part?
nwp
nwp
Yup.
ah ok
thanks!
nwp
nwp
To clarify the previous comment on you being confused: Your teacher probably babbled something about blocks and that reading and writing in whole blocks is faster. That is nothing you need to worry about. Every read and write function knows that and you can just write the whole vector at once, let the implementation do its job and probably gain performance.
13:39
yes but i want to basicly read x bytes for a file in my computer and then send the info trhu a socket to another computer
thats why i made it 512 bytes
because there is a size to the packets
well im getting an error
i tried what you guys sed about removid the HANDLE * file and just use HANDE file and now i use the file (HANDLE) in a function and it gives mwe error in the function
im using SetFilePointer
gives me error 6
ERROR_INVALID_HANDLE
6 (0x6)
The handle is invalid.
why does it give me that error?
the function is waiting a Handle and i pass it a Handle, when i use in the parameters Handle * it works but if i use Handle if says its invalid handle
could i be passing it wrong?
and the vector doesnt store annything
when i tell it to store
nwp
nwp
@jeyejow I'm fairly sure the socket function knows about packet sizes and MTUs and just sending all the data in one call is a better approach.
@jeyejow no idea what your code is doing, probably you're doing something wrong
nwp
nwp
@jeyejow Where did you get that handle from? You should check if that function has failed for some reason.
@Mgetz yes im also sure of that
nwp
nwp
@jeyejow How did you tell it to store? Did the vector even have memory to store something?
13:45
i fixed the handle problem, but the vector is the weirdest problem
@jeyejow I'm fairly sure you probably didn't but again... haven't seen your code
basicliy im usign ReadFile function and one of the parameters is the place to store the information that was read and i put the vector in that parameter
if (ReadFile(file, & _data[pos], quant, &bytesRead, NULL) == 0)
{
std::cerr << "Error ReadindFile! " << GetLastError() << "\n";
return 1;
}
this is how im telling it to store
and this is the parameters of the function were i tell it to store:
static int buffering(HANDLE file, std::vector<BYTE> _data, int point, int pos, int quant)
am i doing something wrong?
nwp
nwp
_data is probably empty so it cannot store anything.
yes, you're reading into a temporary
nwp
nwp
Also that.
13:48
i resised it before calling that fucntion to the size of the file im reading
what does that mean? reading into a temporary?
nwp
nwp
_data is a copy of your vector because you didn't make it a reference to the original.
it means there is no point in doing what you're doing because the data won't be preserved
nwp
nwp
_data disappears at the end of the function, along with the data it read.
so i need to do in the parameter _data& ?
and pass it the reference?
or not pass data in as a parameter, and just return it
13:49
i am confunding vectors with arrays
yes yes you are
i dont want to return the vector, so i just do this in the parameter:
static int buffering(HANDLE file, std::vector<BYTE> &_data, int point, int pos, int quant)
that should work i think
nwp
nwp
What is the returned int for?
so i know if there was an error
ok it worked!
thanks! i need to keep in mind that vector is not array
nwp
nwp
Hmm. Might be the right call, but you should know that exceptions can be a viable alternative.
13:52
i never used exceptions before, im still learning them
@jeyejow throw std::system_error(GetLastError(), std::system_category());
@Mgetz ill try that, thanks!
nwp
nwp
Exceptions are a complicated topic. Throwing and catching exceptions is easy, using them properly not so much.
Usually they shine when you have a task made of small things that can all go wrong.
if something is highly likely to fail, then returning a variant can be a better choice because it forces the caller to check the return.
if something very rarely fails then exceptions can be the better choice because they indicate it was likely used wrong or something crazy happened.
 
4 hours later…
18:16
hey
the problem with learning c++ in books and on the internet now is that all the different versinos of c++ are mixed up
is modern c++ easier to write than old (pre c++11)
?
more like java/c#
?
I'd rather write post-C++11 than Java
for ease or efficiency/spedd advs?
18:18
wow
id have never guessed that modern c++ is easier than java/c#
is this view common?
Maybe not easier than C#, but Java, sure
Java in general has all of this dumb problems you can't easily abstract away
i thought java (practically)== c#
i have only looked at c#
C++ also has problems, but it also allows you to abstract it away more easily
C# OTOH just doesn't have a lot of problems that are in C++ and Java
im at the level to continue this convo now
i am not at **
 
3 hours later…
21:10
"C++ is a multi-paradigm language. Many people associate C++ strictly with OOP."
"C++ should not be simply used like an object oriented language such as Java or C#. Inspire yourself from the STL and write generic code."
generic code is like oop?
not sure why the stl is brought up in an oop discussion
33
Q: What are the often misunderstood concepts in C++?

yesraajWhat are the often misunderstood concepts in c++?

558
A: Why is the C++ STL is so heavily based on templates? (and not on *interfaces*)

jalfThe short answer is "because C++ has moved on". Yes, back in the late 70's, Stroustrup intended to create an upgraded C with OOP capabilities, but that is a long time ago. By the time the language was standardized in 1998, it was no longer an OOP language. It was a multi-paradigm language. It cer...

thanks
21:27
yeah interesting
to me oop and templates/generics solve differnet problems
but then i dont know much
std::vector std:deque are not arrays, they are classes, euh some one is mixing up C and C++ again.
i have no idea what you are hinting at
just saw the starred message there.
std::vector and std::deque are "arrays" by the CS definition of the word "array": they provide O(1) indexed access to elements
they aren't what C++ standard calls "array types", and this matters if we have a discussion
ill keep going
21:39
@milleniumbug once you said std::string isn't an array :S
nvm it's very a philosophical dimension it has a potential to take.
theres so many bits to this language
although to defend myself, this isn't exactly saying that it "isn't an array"
I mean, std::getline specifically accepts a std::string
well think from the context if you can cast an object as an array, if you can't, then it isn't an array.
hello all, I'm looking for an OpenGL GUI library that can run inside an already existing context, namely the one created by libCinder
21:53
imgui comes to mine
That's more for prototyping interfaces isn't it?
yeah
it also seems to be popular with cheat hacks
yeah, I'm looking for something like CEGUI
I'm not sure if CEGUI can integrate with libCinder well though
 
2 hours later…
23:39
Hello
I was wondering if someone could help me with a little bit of code.
2 messages moved from Lounge<C++>
Alright, thank's for the redirect, milleniumbug
Specifically, I've set up three classes, and was wondering if someone could scan over my files for them to see if there are any errors.
does the program do what it's supposed to?
23:46
So, I should compile before asking for assistance?
why else are you asking for "checking for errors" if not?
Because I'm am very new to programming and am paranoid about my skills.
Also, that's a fair point in the "dontask.html" link. Apologies, I should have been more forward.
Also, my program isn't fully finished, I've stopped just prior to writing up the main.cpp file.
I'm unsure what is your goal:
- if you have written code and you want to check it out if it does what it's supposed to, compile it (and at this point it can fail with a compile error), and run it (and at this point it can crash or do a different thing than you expect it to do)
- if you have written code and it does what it's supposed to, but you aren't sure whether it could have been written better, then you're asking for a code review
or are you stuck on some part and you aren't sure how to continue?
My approach to programming is to write thing in parts: write a single function, compile it, possibly write some other function which calls it with a sample data to see if it runs correctly, then when I'm confident whether it works correctly, get to another one
Well, it was mostly a matter of reaffirmation that what I've coded is valid code. I'm new to coding and was hoping for a second pair of eyes to take a look at what I've written. I'm most nervous about a few lines reading "pixels[i].get_red(static_cast<uint8_t>(R));" and similar.
Though, your point that I should try and finish the code before asking for advice is good advice.

« first day (613 days earlier)      last day (2464 days later) »