« first day (374 days earlier)      last day (4576 days later) » 

5:02 PM
I was planning on it
that sure don't look like C++
 
I think everyone must be asleep in the C# room, so they come here because we know shit.
How's that game coming on?
 
I am writing a function where I want to get the reference of another object as argument
Should I make the functions parameter with the & sign
or should I use the type and *
 
@MooJuice yes that is the case.
 
function helloWorld(T& value) {} or function helloWorld(T* value) {}
 
if value can be null, the latter. If you don't want it to be, the former.
 
5:14 PM
If it may be null then?
 
Then the latter. If, functionally, it is OKAY to pass a nullptr to the function, then obviously you have to use the latter (T*)
 
boost::optional.
 
Why?
 
Why not.
 
It depends on the semantics of the function
It either requires something, or it does not.
 
5:16 PM
I don't like pointers.
 
in C#, 1 min ago, by rlemon
I'm reading a binary file and I don't know how large the file is. What is the best way to read until the end of the file? currently I have implemented
 
Fine, use a shared::ptr then
 
is it because this would crash the program: someVariableThatisNull&
 
That's not a valid syntax.
 
it will crash if you call something on it and it happens to be null.
void func(T& val) { val.doSomething(); };
`void func(T* val) { val->doDomsething(); };
 
5:17 PM
@CatPlusPlus Yes, mean Type& someVariableThatIsNull
 
the latter will die if val is null
 
meant*
 
a vector<somestruct> would copy the structs by value inside the vector right? So doing mystruct current = myvector.front() would copy right?
 
We tell the compiler, in the first form, that we expect a valid object. Obviously, that's not guaranteed, but is better than a pointer.
And, as Cat Plus Plus said, if you want to avoid the user of pointers entirely...
 
It's UB to call a member on a null pointer, not a guaranteed crash.
 
5:19 PM
if I changed current in some way, it wouldn't have changed the one inside the vector, is what I'm asking
 
`void func(boost::shared_ptr<T> value) { if(value.get()) value->doSomething(); };
 
That's still a pointer.
 
My first suggestion was a reference.
 
Is it a difference between those two?
 
I was merely accomodating your hatred of pointers :P
 
5:19 PM
And with shared_ptr, you can't pass an automatic variable.
 
If you look away from how you invoke methods on it
 
void func(boost::optional<T&> val) { if (val) val->foo(); }
 
That makes sense only if it is optional.
if it's not, a reference is preferred
 
Didn't say otherwise.
 
I like your username btw
Just out of interest
will boost::optional<T&> allow you to pass a null?
 
5:22 PM
@MooJuice Ah, got one question. If you get the reference from an function....and want to store that reference then you would need to use the Type* reference right?
 
Not a NULL pointer, but it can have no value.
 
and then you need to use reference->someFunction(); instead of reference.someFunction(); ?
 
boost::none is a special value you can use to say "there's no reference there".
You can use reference_wrapper.
 
CPP is right in many ways. I'm not afraid of using pointers internally in classes, but externally...
The thing is
IS it optional?
or are you expecting a valid object?
 
You can have reference members, but they're more trouble than it's worth.
 
5:25 PM
If your function can be called with an non-existent object, perhaps boost;:optional is the way to go
If your function expects it, use a reference
 
And yes, you probably don't need null semantics.
 
You should default to passing by plain reference, or even by value.
 
Okey
Thank you guys
 
But I agree with CPP on the boost::optional stuff, if it is indeed, optional.
(and you wish to avoid passing naked pointers around)
 
5:28 PM
.section .rdata,"dr"    <-- What does "dr" signify?
 
If I have a baseclass and want some of the functions to be overridden by subclasses then I need the virtual keyword?
Otherwise it won't work?
 
@BPDeveloper yes
 
do I add the virtual keyword in the definition too?
 
@BPDeveloper specifically, each function you want to override needs to be a virtual function.
 
5:32 PM
You don't need virtual if you always work with the derived type.
 
true
 
Though you still want to make the dtor virtual.
 
@CatPlusPlus But doesn't the .section .rdata already says that by itself?
 
virtual keyword both in header and cpp+
 
you need virtual if you are trying to call derived functions via a pointer to the base class
 
5:32 PM
?*
 
@FredOverflow Section names are arbitrary.
 
Really?
 
BDeveloper, is if it is an abstract class, remember to use virtual ~myclass() = 0 { };
 
virtual keyword both in header and cpp?
 
There are conventional names, but you don't need to use them.
 
5:34 PM
or a reference to the base class
 
But still:virtual keyword both in header and cpp? or just header
 
@BPDeveloper i think you only need it in the header
 
The virtual keyword, and other modifiers are only required in the header file.
In your implentaton file (.cpp) everything is business as usual.
 
So in the sub class I just write the same function header and it works?
 
@BPDeveloper yes
 
5:39 PM
But do I use the Superclass::functionName or the name of the subclass?
 
Evening
 
@MooJuice cv qualifiers need to be in both.
 
@BPDeveloper subclass::function_name() when you define it for the subclass
@ManofOneWay afternoon
 
Error: inherited member is not allowed
 
@BPDeveloper without seeing your code, I'm not sure where that error is coming from
@BPDeveloper it may help to implement a minimal test case and get that working just so you can have a reference for what you are trying to implement
 
5:46 PM
I think I found the error
I need to write the same function prototype in the subclass when overriding?
 
mawnin
 
0
Q: difference between NULL & 0

CAD_codingI have a class CS which is to represent the co-ordinate system in 3D i.e.(x, y, z) class CS { private: double x; double y; double z; } I want that the user can create a CS (0, 0, 0). In the constructor i want to initialise the address of x, y & z to NULL. this is ...

Argh.
 
warning: fail detected
 
> Primarily, i want to manually assign 0x000000 address to any variable
cringe
 
5:53 PM
Language wars!
2
Q: Why is C# much slower than Java and C++ in my prime number testing

user997112(bear with me, there's a lot of explanation before my question) As a few of you may be aware over the last few days I have posted a fair few questions relating to performance of C++. Being a Java programmer I wanted to know was C++ worth the extra effort to specialise in, or is Java good enough ...

 
I just wrote some code that took a "type pack" (not sure that's quite the right word, e.g. Args in template <typename ...Args>), recurses over it and potentially changes one or more of the types based on the return values of a constexpr function - is that reinventing the wheel? (i.e. is there some pre-supplied function that would do this for me?)
 
@Praetorian double cringe
@awoodland MPL probably has a map or something.
 
@CatPlusPlus Best of all, he did his "benchmarking" in Debug mode on all
 
@Praetorian They all do.
But the "language has speed" concept is worse for me.
 
@CatPlusPlus - closest I could see is: boost.org/doc/libs/1_40_0/libs/mpl/doc/refmanual/replace.html but that's just based on type equality
 
@CatPlusPlus - that still doesn't quite cut it because the transform I applied considered the position within the list
i.e. the unary transform could be different for the first type compared to the second type
I used it for populating a container of all the possible permutations of combinations of const and non-const for a given typelist
 
Dunno, I don't use MPL.
 
6:13 PM
@CatPlusPlus it's a common misconception that only implementations have speed, and that languages do not. e.g. python programmers think so. that's because they have an inferiority complex and can't accept that their language is very very slow. pure c++ programmers tend to not think that way. that's because of nothing to be ashamed of.
 
0
A: Detecting if a browser is using Private Browsing mode

XaadeWait, so you're not going to block them if they don't have private browsing enabled? If that's true, why have a smart message box at all??? Would attempting to set a unique cookie work for all browsers and platforms? Anyone done this before? I think the most elegant solution would be to: ...

The highest voted answer is a little ridiculous. Rolling a custom browser. The OP just mentioned that he has no control over access [point, location, and technology].
 
@AlfPSteinbach Eh? PyPy is not slow. Also there are unoptimising C++ interpreters.
 
well within c++ the same kind of "controversy" is about iostreams. look, dietmar kuehl's implementation is not slow. also there are needlessly unoptimized version... the fact is, iostreams are generally sloooooooooooooow. due to the lack of design.
 
@AlfPSteinbach The way a language compiles is implementation is it not? And some language features have only so many ways of implementation. I think that's where a language can impact speed. You can't implement a linked list, without links.
 
fast question:P is this correct in assembly mov EDX, [EDX + 8] ?
 
6:23 PM
how the hell should we know?
 
@AlfPSteinbach Like how ugly women claim that all women have beauty. Yeah right.
 
@StackedCrooked attitude is half of beauty, so there's some truth in that.
 
@AlfPSteinbach iostream has lack of design? Can you elaborate a little bit on that?
 
beauty is also subjective, so it depends on who you ask
 
Perpetually bitchy supermodels aren't that beautiful after all.
 
6:32 PM
@StackedCrooked where else in std library do you find 2-phase initialization? that alone is enough to say it's fatally flawed. like observing a car with at least one square wheel
have you ever used an iostream "observer" (that's the name used in the spec)?
 
Nope. I'm not too familiar with the possibilities of streams in C++.
 
exercise: using only std library, write a Windows program that copies input to output exactly
 
Binary?
 
of course
it's interesting that josuttis got that wrong in his book, presenting a program that would only work in *nix
 
what do you mean by input? source code?
 
6:36 PM
memcpy? (Is part of std I believe.)
Or a for loop that copies byte per byte..
 
@bamboon any windows process and any *nix process has (at least) three standard data streams: input, output and error. when nothing else is specified, that's the default meaning of "input" and "output". especially in the context of iostreams.
 
Aah.
So you mean an application that can be called like this: cat data.bin | myapp > data2.bin. And in the end data.bin must be identical to data2.bin.
 
ahaa ok, i still dont see what to do
 
@StackedCrooked yes. though without assuming you already have a program with that capability.
 
I'll give it a try.
 
6:41 PM
oh, the point was, you can't
 
@AlfPSteinbach really? Why can't you?
 
@codemaker because of lack of design of iostreams. they don't support that. of course it's no excuse that FILE* don't support it either.
i think those "can't do that" programs tell a lot about what's good and what's bad
 
@AlfPSteinbach is cin on windows not a binary stream?
 
@codemaker yes, it's binary at the OS level. with some other language the task is trivial. at the iostream level it imposes text conversion.
another "can't do that" program: implementing Window's 'echo' command in standard C++.
 
@AlfPSteinbach ah ok. And there is no way to close it and reopen it as binary?
 
6:44 PM
it's pretty silly what one can't do
@codemaker not with standard library, at least, not without special-casing each OS
 
@AlfPSteinbach ahh ok. shrug I guess you could consider that a problem with iostreams. Does the standard say that stdin and stdout are not to be binary?
 
@codemaker check it?
 
@AlfPSteinbach too lazy, also I don't care enough to know
just wondering if it is an implementation issue or a standard issue
 
@codemaker given the context of the discussion, what do you think it is?
 
What do I do if I want to set a subclass variable to a superclass variable?
 
6:51 PM
@AlfPSteinbach well I'm not sure. Given your position, I would say it is a standards issue.
@BPDeveloper use superclass::var_name to reference it
 
I mean
Animal animal;
Dog inherits from Animal
how do I set dog instance to Animal type variable
 
Dog dog;
Animal& animal = dog;
 
use a reference or a pointer
Dog rover;
Animal& animal = rover;
 
Also, it's a silly hierarchy.
I win.
 
heh
 
6:54 PM
Cat plus_plus;
Animal* animal = &plus_plus;
 
Why pointer?
Why can't I just do Animal animal = dog;
 
Don't use a pointer, unless you really need it.
 
because someone thinks this is C
 
no, you should use a reference, but depending on your needs, you can use a pointer
 
Animal animal = dog; slices the object.
 
6:55 PM
?
 
You're left with only Animal part of the Dog.
 
#include <iostream>

int main() {
    while (std::cin.good()) {
        int n = std::cin.get();
        if (n == -1) {
            break;
        }
        std::cout.put(std::ostream::char_type(n));
    }
}
 
Animal animal = Dog();
 
^ Doesn't seem to work though.
 
what about that? is it the same?
 
6:55 PM
It's like fitting the dog into a shoebox by cutting everything that doesn't fit.
 
Animal animal = dog won't work because unless you access the thing through a pointer, C++ doesn't know it's really a Dog -- and it won't copy any Dog-specific fields or use Dog's vtable
 
@CatPlusPlus Can you do Animal animal = dog? Won't that look for an == operator?
 
@codemaker Why would it look for == operator?
 
er an '=' operator
actually, no that would do a copy op
 
operator= will either be generated or be provided, but it'll be there.
It'll be looked up on Animal, but remember that reference binds to a derived type.
Something like that.
 
6:57 PM
So if I do Animal animal = dog;
then only Animal functions etc is available right?
 
It's not what you want, in any case.
 
@codemaker you could do it, but you wouldn't get the results you expect. animal looks like a plain old Animal, and animal.makeSound() wouldn't bark, for example
virtual or not
 
But if I want the dog to bark when it is reference through an Animal variable how do I do it?
 
@cHao right, I was thinking that animal = dog wouldn't even work
@BPDeveloper Animal& animal = dog; animal.sound(); // will bark like a dog
 
animal& a = dog; a.bark(); calls dog::bark(), assuming appropriate polymorphism
 
6:59 PM
operator= usually has a signature T& operator=(T) or T& operator=(const T&).
 
@codemaker it won't "work" the way you expect. it's syntactically valid, but has issues that make it useless for the general case
 
ahh yes, of course
 
In case of the reference, it can bind to an object with derived type.
 

« first day (374 days earlier)      last day (4576 days later) »