« first day (550 days earlier)      last day (4397 days later) » 

user1174868
12:13 AM
Can anyone explain to me what the ampersand (&) does in a void function of c++? In class it was explained that it clears the value but from waht I see is that it will store the value of that variable and overwrite the original
 
That question makes 1% sense to me. & means a variety of things in different contexts, and I can't think of any time when that context depends on whether or not you're in a function returning void. Do you have a code sample?
 
user1174868
void test(int first, int& second);
 
That's a reference. It doesn't have anything to do with void.
 
user1174868
well what does it do
 
It refers to a variable, instead of making a copy.
void test(int first, int& second) { first = 5; /* assigns 5 to first, which happens to be a copy of the function argument */ second = 7; /* assigns 7 to second, which refers to another variable somewhere */ }
 
user1174868
12:30 AM
so it can change function in the main body? so for example if x and y are changed in the function(int x, int&y) only y would change in the main body, x would only change with the output of the fucntion but y would change anywhere it is used?
 
user1174868
I guess I just dont understand this code
 
user1174868
 
user1174868
so when a function is called with different inputs those inputs get changed with the ampersand correct?
 
Yes, the variable refers to an existing value.
 
user1174868
I haven o fucking clue what this function wants
 
user1174868
12:39 AM
the function definition has cin a, b, c, d but then the function call is function(fourth, third, second, first,)
 
user1174868
what the hell does that even mean?
 
user1174868
why would a function accept cin, where is the cin from? I dont get it
 
user1174868
this book is dick
 
user1174868
I want to ask this question so I have to spam answers
 
has anyone else here experienced problems connecting Windows 7 to a Samba share?
@Xaade multiple?
@Jordan it's a global, from the standard library
 
user1174868
12:53 AM
I just dont get that code at all
 
user1174868
I have the answers but I cant make it right
 
what you trying to learn?
i just woke up and it's the middle of the night
 
@CheersandhthAlf Some discovery/connectivity issues but they never last.
 
user1174868
I just found out I suck at everything I do
 
@LucDanton well for me it just refuses to even see the server, unless I ping it first, in which case it refuses to see the shares, and then mumble mumble no such network path blah...
@Jordan in that case, a job as a tester of milkshake straws, or perhaps a prostitute, might be JUst The Thing(TM).
:-)
 
user1174868
12:56 AM
I would love to be a prostitue, but I don't look good
 
oh, shit
or "tough luck", as they say
 
user1174868
Yeah it is hard being me
 
@LucDanton I did try to adjust the security level (in order to make it try old ways of negotiating connection), but that didn't help, and yes I rebooted, a few times
@Jordan well then, what's the code?
 
user1174868
This guy typed it up
 
user1174868
12:59 AM
I can't understand the last output, when that stupid function calls that crap in reverse
 
well let's start at the top
 
user1174868
fourth = first * second + third - fourth; //line 8

goofy(fourth, third, first, second); // line 9

cout << first << " " << second << " " << third << " "

<< fourth << endl; //line 10
 
declaring the function above main, that's just extra work.
simply define it above main.
 
user1174868
I dont get what it means to have value for the function input in the function call and then have the function give cin inputs that are different nunmbers, I don't know what does what
 
user1174868
This is just a homework proble mfor the class that I have spent an hour too long on
 
1:00 AM
How well do you understand pass-by-reference?
 
user1174868
I dont know what that means
 
the point is probably that it's meaningless
so that you need to be relatively sure about things in order to dismiss it :-)
but, right, the input operation overwrites the values set earlier in main
so those values are just gone
 
Speaking of, what is the assignment in fact? What do you have to do with this code?
 
user1174868
Just find the output for the specified inputs
 
Are those two sets? Nevermind, should be a 'trick'.
 
1:03 AM
oh that's simple: run the program
 
user1174868
I just dont get how the output is 7 5 6 2
 
user1174868
I can't get c = 7
 
So beyond the assignment you want a better understanding of the code, correct? This is not about the homework itself.
 
user1174868
Yes
 
@Jordan right, that's impossible
 
user1174868
1:06 AM
I have the answer but I don't quite get how they got the answer
 
user1174868
The answer is in the back of my book
 
but it is not c that is 7
 
Tbh I'm not sure how to go on explaining pass-by-reference.
 
user1174868
c is the first output?
 
user1174868
I guess I just don't quite understand the ampersand yet
 
1:11 AM
You forgot to mention there's a corrected version of the program later on in the thread.
 
user1174868
I am just reading it out of my book, I used that to show you guys
 
user1174868
if I have a function that is void (mickey(int&a, int b) { int first; first = b +12; a= 2*b ; b = first +4; }
 
There are sites like ideone where you can in fact paste the program of interest and test it yourself btw.
 
user1174868
where b = 5
 
Oh yeah, one can explain references regardless of function calls.
 
user1174868
1:15 AM
I dont know what that word means, reference
 
A reference variable will refer (not saying much right now) to an object and will behave as if you operated on the object itself.
For instance with int i = 0; int& ref = i; ++ref; then after that snippet i == 1 holds.
Just as if you'd have done ++i directly.
Does that make sense?
 
user1174868
no
 
If you have int i = 0; ++i; then i == 1 holds, you're with me on this right?
 
user1174868
yes
 
1:20 AM
If you do ++ref in the previous snippet the effects are the same as if ++i was done.
Because ref refers to i.
 
user1174868
so x& inside a function is then a "reference" outside the function?
 
user1174868
why?
 
user1174868
how does it know i?
 
I'm not sure what you mean. Are you comfortable with the code fragment that uses a reference right now or not?
I.e. int i = 0; int& ref = i; ++ref;
 
user1174868
I don't know ref
 
user1174868
1:21 AM
I have never seen it before
 
ref is a variable name
 
user1174868
I dont really know &
 
user1174868
oh
 
int i = 0; int& b = i; ++b; behaves the same.
 
user1174868
ok
 
1:22 AM
int& b = i; is 'define a variable b of type int&', where int& is the type 'reference to int'.
 
user1174868
so int b=5, int&b = 0 are both true?
 
Can't have two definitions with the same name, I'm not sure what you mean.
 
user1174868
well if I have b = 5 and b = 6 what happens?
 
user1174868
I just dont get what & does
 
In this instance it's not an operator or anything, it modifies a type
 
user1174868
1:24 AM
a type of what?
 
Much like int[42] is the type 'array of size 42 and element type int', if you're familiar with that already.
If you aren't then sorry that won't help.
Are you?
 
user1174868
slightly
 
is there a difference between:
 
Okay, so some types can be constructed from other types. Reference types are among those.
 
user1174868
so int& is a type of integer
 
1:26 AM
struct Thing x;
and Thing x;
 
@Jordan It's the type 'reference to int', in full. Whereas int is just by itself.
int& is not an integral type, if that's what you mean.
 
user1174868
so in a function call when I use function(int&a) that means that whatever is the first variable input is being replaced by whatever the fucntion says?
 
It's not replaced necessarily, but the function has access to it and can certainly change its value wholesale.
for instance void do_nothing(int& r) {} int i; do_nothing(i); is pretty harmless. CBA to make that example work.
@newprogrammer No difference most of the time in C++.
 
so it's just for clarity?
kk, thank you Luc Danton
 
user1174868
so if I have void minnie(int u, int&v) { int second; second = x; v= second + 4; x = u + v: } where x = 6
 
1:30 AM
@newprogrammer Arguably struct Thing x; will surprise some programmers whereas Thing x; should not.
 
user1174868
u and 10 and v is 5
 
it surprised me indeed
 
user1174868
what is the output?
 
There's no output in the traditional sense. Do you mean e.g. the value of v?
 
user1174868
well then it out puts first second and x
 
1:32 AM
where is x coming from
 
user1174868
x = 6 defined in body
 
user406009
@newprogrammer struct Thing x; was how you had to do it in C, structs were not automatically put in the normal name set.
 
i see
 
Which I find really strange, since you could typedef it and make it look like C++.
 
user406009
Of course you might still see Thing x; in C code due to typedefs. Ah, beat by Maxpm.
 
user1174868
1:33 AM
ok
 
I'm not sure what the rationale was for struct Thing x.
 
user1174868
I have a better question, if I have a void function(int& a, int b) and cout a b
 
@Jordan second has value 6 and x has value 15. Probably. You could try on ideone.
@Maxpm C.
 
user406009
@Maxpm Avoid name collisions when the feature was introduced?
 
user1174868
b will be whatever it is defined as in the main body and a will be whatever the function does?
 
user406009
1:34 AM
That seems to be the reason for doing most things in C or C++.
 
@Jordan Not quite.
 
@EthanSteinberg That's probably it, actually.
 
@Jordan int& as a parameter type isn't much different from int in this case: for both a and b it's like they are variables that are created with whatever was passed at the function call. So if you have void foo(int& a, int b); and call the function like so: int i = 42; foo(i, 50); then inside foo b has value 50 and a refers to i, which has value 42.
So even if foo 'does nothing' a will refer to something with a value.
 
user1174868
so if I want to return a value to the main body and I have to use a void function I have to use int&?
 
That's one way to do it, yes. Likely the most straightforward, too.
 
1:39 AM
anyone know how to create custom combination functions (i am assuming recursive)?
trying to generate all combinations meeting some conditional without wasting iterations
 
user1174868
are there any good videos on c++? All the ones I see either don't go into detail at all and are worthless or are way over my head
 
@Jordan Videos to learn?
 
user406009
@Jordan Books are the best.
 
user406009
Download the pdfs and read them on the computer.
 
user1174868
yes videos to learn, my book is horrible and they are really expensive
 
user1174868
1:42 AM
anyways if I have a function how does it execute, for example if I have {x= 5 cout x x= x +5 }
 
user1174868
what is the output?
 
@Jordan: You want books. One of these: stackoverflow.com/questions/388242/…
 
user406009
The main "good" videos on C++ are ones on specific topics. Such as networking, threading, etc. Not really for general learning.
 
@Jordan I'm not so sure videos will be any more useful.
Yeah.
We're always here to help if you have a specific question.
 
user406009
@JohnSmith Here is a cool idea, although I am not quite sure how useful it would be.
 
user406009
1:45 AM
Have a bitset of all of the objects.
 
user406009
Increment the bitset's integer value by one, and that is the next combination.
 
@Jordan 5.
 
well, what i have is a list of primes and another list of exponents for those primes. i am trying to generate all subsets of possible primes and then start raising their powers such that the product of it all is underneath some limit.
 
user406009
Sounds like a good question for this site itself.
 
however i don't want to bother going to combinations that obviously will be over limit; if i know that a^x*b^y*c^z is over limit then so will anything with a higher exponent on any number etc
 
1:46 AM
@Jordan You mean, if your function were like this?
void foo()
{
	int x = 5;
	cout << x;
	x = x + 5;
}
It will only print 5.
 
user1174868
ok
 
user1174868
thank you
 
user406009
@JohnSmith I think this might work best with some sort of graph searching algorithm.
 
First, the x variable is initialized with a value of 5. Then, the value of x is printed. Then, x is incremented by 5.
In that order.
 
user406009
Each node is a set of exponents, with each path incrementing the exponent by one.
 
user406009
1:50 AM
Once a path has "reached" the goal, it will no longer be explored.
 
sure
 
2:13 AM
hey, sorry if this a dumb question, but if you add objects to a queue
then pop them
will their destructor be called?
 
Yes.
 
@GManNickG any idea how to do the recursive combination thing with conditional?
 
class Obj
{
int* x;
public:
Obj() { x = new int;}
~Obj() {delete x;}
};

int main() {
queue<Obj> objQueue;
objQueue.push(Obj());
objQueue.pop();
}
@GManNickG so you are saying this leaks no memory?
 
@newprogrammer no, it has other problems. look up rule of three
 
please do tell
which one am i missing
 
2:19 AM
consider what happens when it's copied
 
oh i'm missing two
 
then you have two (or more) objects that each think they should delete
 
i am familiar with rule of three, i just didn't include it in this example
Thanks for the warning though
 
It is interesting exercise to make a "clone_ptr", similar to "unique_ptr"
 
I do not know what a clone_ptr is
 
2:21 AM
unique_ptr enforces single owner and ownership transfer
while a clone_ptr will automatically clone the referred object when itself is copied
 
how is this different from a shared_ptr
 
a shared_ptr shares ownership
 
oh i see
 
You kids and your *_ptrs.
 
that's what the "shared" means
 
2:22 AM
so you can delete clone_ptr's independently?
 
you might say, clone_ptr is the mysteriously missing smart pointer in the standard library
 
@CheersandhthAlf By "ownership," you mean the expectation that code outside a certain section will not touch the pointer?
 
i believe so
 
ownership of dog means you're responsible for the dog, like, cleaning up after the dog
 
smart pointers just make it easier to enforce ownership
 
2:24 AM
of course the dog thinks that it is the master
after all, it is the one shitting, and you're the one cleaning up
and so, maybe, it is with raw pointers
when you own a raw pointer, you must clean up after it, like calling delete
and you will time and time again find that the raw pointer goes its own ways, thinking it is the master
 
What about a weak_ptr
code that has a weak_ptr doesn't have any ownership of the pointer at all
yet you can still "touch the pointer"
 
it has a shared ownership
weak_ptr is just an adjunct to shared_ptr
it does not make sense without some original shared_ptr or set of shared_ptrs
 
54
Q: Rule-of-Three becomes Rule-of-Five with C++11?

XeoSo, after watching this wonderful lecture on rvalue references, I thought that every class would benefit of such a "move constructor", template<class T> MyClass(T&& other) edit and of course a "move assignment operator", template<class T> MyClass& operator=(T&& oth...

Does this mean I have to define more special member functions now
 
it depends on how automatically the move constructor and assignment op are generated
i'm not sure
there was a big change following scott meyers' pointing out how the automated generation could wreak havoc with existing code
lots of people joined that fight on scott's side, including me, then when apparently things would be fixed we or at least i just forgot about it
so not sure exactly what the outcome was
 
"Note that move constructor and move assignment operator won't be generated for a class that explicitly declares any of the other special member functions,"
I guess that means you can still just do Rule of Three
you won't be able to use move-semantics with that class though
 
2:44 AM
hm, gnome editor "gedit" defaults to running with no window. how extraordinary dumb is that
i had forgotten why i made a wrapper script for that command :(
 
What's gnome editor
 
@newprogrammer The text editor that comes with the GNOME desktop environment.
 
@JohnSmith Sorry I went afk after my last message. I didn't read your problem statement, what's up?
 
3:16 AM
in Visual Studio I am having trouble finding stuff
warnings pop up
then they disappear when the program runs
where do I see those warnings again
it wont let me declare a really long vector either
 
@JohnSmith there is an "output" pane at bottom. i think in the View menu you can show it. there is also a shortcut key
 
found it anyway
 
the problem now is that it wont let me declare a rather large vector
i am using a vector to memoize
 
just use std::vector
 
3:28 AM
i am
 
it should not react to the size in the declaration because that's a run-time thing
 
it does
 
nope
try with a small size
 
well, when i try to run, it bails out saying it's too large
 
then it's really large
:)
 
3:29 AM
you are right though, it does crash at runtime
 
how large?
 
errrrmmm. like 10^12
 
oh my
4 GB is 4*10^9 bytes
so you want about a 250 times that
it's too much (today)
 
shit
it's either that or i figure out this combination thing
which seems implausible at this pt
 
probably the problem is designed to not be solvable with brute force
i think
 
3:32 AM
it's not brute
it's memoized
 
well, force
 
XP
i am trying to find a quick way to get prime factorizations of numbers iteratively
so say i have 12. i can break this into prime 3 * remainder 4
the 4 i have calculated already so i can use that
etc
as I go up N I can keep using results i've already calculated
 
you could perhaps use erastothenes' sieve
unsure of speling
 
how does that apply here
i thought that just finds all primes <N
 
3:34 AM
the challenge is in finding prime factorizations of all numbers in a range
if you use naive algorithm for each one you wind up re-doing a lot of steps, so i am trying to memoize
 
well the result of the sieve appears to be precisely what you are trying to memoize
except instead of a list of numbers it's a bitset
but that's just representation
how large a range are you talking about?
 
I can just show you the problem
 
Urgh. How on earth do I get a file descriptor from a file name?
 
3:37 AM
@Maxpm the os api?
 
just to save you the time, f(n) here is the same as tinyurl.com/7577jtg
which is the same as taking all the exponents of the prime factorization of n, changing them to (2*exponent+1), multiplying them all together, adding 1, then dividing by 2
e.g. f(12) = 2^2 * 3^1, exponents 2 and 1. -> (2*2+1)(2*1+1) = 5*3 = 15. (15+1)/2 = 8
 
@CheersandhthAlf I can't find any docs for it for Linux. Everything that turns up is going the other way.
 
@Maxpm oh. well in the old days you had the whatsitcalled number directly in the directory entry. you could just read the directory as a file.
@JohnSmith i think that's too heavy for me ;-)
 
why?
i am just trying to figure out a good way to get prime factorizations quick
 
@JohnSmith: What is the big picture of the problem you're trying to solve?
 
3:41 AM
i don't grok the problem. i do know how to compute least common multiple.
 
i just explained what f(n) is actually equal to
you dont need the lcm thing
@GManNickG Finding a fast way to get exponents of a prime factorization either iteratively/with a sieve as to save time
 
@JohnSmith "get exponents of a prime factorization" But why? What's the final goal?
 
finding g(n) which is the sum of all f(n)
where f(n) =(((2*exponent+1)*(2*exponent+1)*...for all exponents of the prime factorization of n...)+1)/2
e.g. f(12) = 2^2 * 3^1, exponents 2 and 1. -> (2*2+1)(2*1+1) = 5*3 = 15. (15+1)/2 = 8
 
Oh, so for Project Euler. That's what I mean by overall goal.
 
yes
i have the right idea but C++ doesnt let me declare large vectors
maybe need a map
 
3:46 AM
@JohnSmith This isn't a C++ thing, it's a computer thing. You simply cannot allocate 1000 GB of data at a whim.
You're probably approaching it wrong. Most of those problems aren't going to be solved by brute force or iteration, you're suppose to find some mathematical simplification and use that; which is obviously a math problem, not a computing problem.
 
I already figured out the math part
now it's a matter of figuring out a good way to handle the computing
maybe i dont need to hold everything in memory
like once I have prime * its remaining composite... actually eh that wont work
i tried making a combination-generating function that requires no memoization but i couldnt get it working
i.e. generating all valid combinations of primes under N and then all combinations of valid exponents such that the overall product is <N
which is why i was asking you earlier about recursive combination generators
 
user406009
There might be some trick related to the sieve.
 
i already have a sieve that'll generate all primes under N
 
user406009
Thinking about it, you could probably calculate the number of numbers with factors of 2, as you go across the row skipping one that would give you factors of two.
 

« first day (550 days earlier)      last day (4397 days later) »