« first day (32 days earlier)      last day (4909 days later) » 
00:00 - 20:0020:00 - 00:00

12:03 AM
@Alf ohh good idea!
 
 
2 hours later…
2:17 AM
Why do you have the '.' at the end of 'return 0;'?
 
@tina it's a peculiarity of Microsoft's compiler and linker; by default it does not accept a standard main for a GUI subsystem program. A GUI subsystem program is one that doesn't get an automatic console window. If you're using Visual Studio, easiest way to fix is to create a new "project" of the right kind, producing a console window app, and copy your code over.
@david Perhaps @tina has been exposed to Pascal (Pascal requires a single period at the end, if I recall correctly)...
 
@AlfPSteinbach I'll let you in on a secret, I'm not actually a c++ programmer, so I wasn't sure if it was maybe meant to be there or not.
 
Good guess, then. :-)
 
2:56 AM
@tina I'm not quite sure what you're exploring here, but it's good to see you doing real code (because that makes questions more concrete :-) ). I presume next step would be to replace your set_values with constructor.
OK, no-one else talking here so I'll just skip adding @tina all the time.
Now, the tutorial you linked to shows "getter" functions. Those are mostly OK. They allow you to change the data representation while not affecting code that uses the class. That's Good(TM).
Setter functions are very different. In C++ they're generally Ungood(TM). In some other languages they have benefits that they don't have in C++, so, much used in Java for example (where they are used by tools).
Consider a rectangle with not only width and height, but also a position x y.
yes, but if you let "client code" (code using your class) use your member variables directly, then the representation can't be easily changed. also, you then risk the client code messing up things. it's almost guaranteed, except for very simple classes like Point
now you asked a hard question and i'm trying to answer it as short as possible...
consider that rectangle with position and size. one possible setter is setSize. another is setPosition. a third is setCoordinates (setting upper left and lower right corners). and more. depending on how you choose to represent the rectangle at least one of these will be utterly trivial. the others, involving at least some simple add or subtract.
the setPosition and setSize setters are good, because there can be very little confusion about what they mean, what the effect of specific arguments will be
the setCoordinates setter is ungood, because there are at least 2 main ways to represent a rectangle with coordinates. one way, the coordinate of pixel inside lower right corner is used. other way, coordinate of pixel down to right of lower right corner is used, i.e. (x1, y1, x2, y2) = (x1, y1, x1+w, y2+h). that's used e.g. in Windows API graphics. it's a common source of "off by one" bugs in graphics. it is easily avoided by not letting client code mess with your representation.
and, to do that, establish valid data in constructor, don't make representation accessible to client code, provide only setters and operations that are very clear, very difficult to use incorrectly
ok, that's it. :-)
 
4:11 AM
:)
 
4:26 AM
The error message doesn't correspond to your pasted code.
But that's the compilers fault, not yours.
Sorry, I didn't see that. Compilers often issue misleading error messages.
The error on line 19 is that you write set_values(int &b,int &a);. Remove the int s
But then, when you get that to work, there is no good reason to use pointers as arguments. At least as I can see. So simply change set_values back to non-pointer arguments as it was originally. And change the call accordingly.
#
CRectangle::CRectangle(int a,int b)
{
set_values(int &b,int &a);
}
(That code snippet is where the incorrect int s are)
yes
check the line where the first reported error is
 
@JeffAtwood Someone wants to pay $75/chapter to criticize a book? That sounds like fun!
 
did you remove the int s on line 19?
 
what he means is instead of "set_values(int &b,int &a);" do "set_values(&b, &a);"
 
so what is your line 19?
 
change it to
set_values(a, b);
 
4:40 AM
tina, i'm almost giving up on you. i can clearly see the word "int" repeated twice there
:-)
 
She is misunderstanding you
 
tina that's good. communication is hard sometimes. but it works out in the ned.
 
what did you change tina?
yeah, that's what he meant by 'int s'
 
I don't know enough about c++ to answer that. I think you are probably right, but maybe wait for Alf to come back
What do you mean by 'enough'? Do you want to know how much space your object takes up in memory? Like how an int takes 4bytes?
I don't know how big the stack is. I think the stack is good for temporary objects, so they get removed from the stack quickly. If your CRectangle is just used for a temporary calculation maybe it's okay to put it on the stack. But if you want to use the rectangle for a long time, put it on the heap.
I will let someone smarter than me answer though, I am going home now :) see you all later
 
5:54 AM
ah good to hear that
 
6:15 AM
Peeps... I'm getting a weird error compiling something. What's wrong with this?
class c_x { public : c_x() {} y(CString c) {} } x;
x.y(_T(""));
VC++ tells me that x is being redefined
anyone, anyone? Beuler? Beuler?
Sure
@David any thoughts?
 
@MikeCaron Just that code?
 
Yup
Visual C++ 2008
 
What kind of "redefined" error do you get? Is it a "this variable is being redefined" or a "this object has multiple definitions" type of error?
 
@James the first
C2371
'x' : redefiinition, different basic types.
Let me adjust the code a bit...
no.. no adjustment needed, that's it.
 
y has no return type.
 
6:24 AM
I put "void" before y and I still get the same error :(
class c_x { public : c_x() {} void y(CString c) {} } x;
x.y(_T(""));
 
#include <atlstr.h>

int main()
{
    class c_x { public : c_x() {}  void y(CString c) {} } x;
    x.y(_T(""));
}
That compiles without error.
 
Yep... that's right. Just tested it alone.
hmm... that's weird.
 
Where does it say that x is previously defined?
 
on the line x.y(_T(""))
There's some code before and after those two lines, but if I remove those two lines, the file compiles without error. I add those lines and I get this funky error.
There's no name collision.
 
The error should identify both lines: one will be the line on which this x is defined and the other will be the line on which x was previously defined.
 
6:27 AM
So there's actually 3 errors:
1. error C2143: syntax error : missing ';' before '.'
(line of x.y)
2. error C4430: mising type specifier - int assumed. Note: C++ does not support default-int
(line of x.y)
3. error C2371: 'x' : refinition; different basic types
see declaration of 'x'
for both lines
 
Are you looking at the output window or the error window?
 
So it's not recognizing the class definition because it's telling me there's a missing ';' before the '.' (i.e. the identifier is not a type)
rather the identifier is not a variable, that is.
 
Are you looking at the output window or the error window?
 
Error window (i.e. "Output tab")
 
There are two windows: the Output window that prints the output of the build and the Error List that lists the first line of every error in the Output window.
You have something else wrong in your source file.
 
6:34 AM
@James yeah, just trying to find it is a B*tch
This is a pretty big file
 
I'm designing this class that I expect will be used in STL containers. I can override operator< so that list<MyClass>::sort() works well, but I'm not sure how to handle list<MyClass*>::sort()
 
@AlexW: That would be a good question to ask on stackoverflow.com.
(I'd answer it here, but the more questions asked/answered in the chat, the less questions there are permanently available for others to find on Stack Overflow.)
 
fair 'nuff. I could use some more rep anyway :)
 
the faq on sequence points already had paid off I think :) We have had another wave of i++ + ++i questions these days. (Who comes up with those, anyway? And why?)
 
6:49 AM
@FredOverflow Ha. I saw the link in the feed and ignored it :-P
 
@JamesMcNellis it's already closed after 7 minutes :)
 
Wow, there's something really F*d up about this. @James, I commented out EVERYTHING in the file except the two class lines. I did a compile file on it only, not the whole project and it still barfs.
I transfer that same code to a new command line project and it compiles fine.
wtf?
 
"EVERYTHING in the file except the two class lines." And the header inclusion, right?
 
yes.
Check this... I've changed those lines to look like this:
#include <windows.h>
HKEY _myK;
RegOpenCurrentUser(KEY_READ, &_myK);
I get the same situation...
RegOpenCurrentUser : redefinition; previous definition was 'function'
huh?
 
You created a source file with the following contents:

#include <windows.h>
HKEY _myK;
RegOpenCurrentUser(KEY_READ, &_myK);
 
6:57 AM
Yep
That's it.
 
Well, of course that's an error. You need to put that into a function...
 
Why?
Oh...
So this file is in a project, and the project has a main in it. All I'm doing is <ctrl>-<F7> to compile this file alone.
It's not linking, just making an obj file... there shouldn't need to be a "main" fn
hmm... wraping in 'void main() { ... }' did the trick.
why?
 
@MikeCaron you can't have global statements in C++
 
That should be int main() .... main returns int. Always.
 
@fred hm. k.
Ugh... now I look things over and I see what you guys mean.
Thanks for the help.
I need more coffee...
 
7:05 AM
No problem.
 
@JamesMcNellis do we have a faq on that?
 
I was kind of hoping that @AlexW was going to ask that question of his on Stack Overflow... I prepped an answer and everything :-P
@FredOverflow A FAQ on the fact that statements can't appear at namespace scope?
 
I found a really similar one, so now I'm not sure if I should post it
 
The most common answer I've seen is to use a struct/functor thing
 
7:07 AM
template <typename T>
struct indirect_less
{
    bool operator()(T* x, T* y) { return *x < *y; }
};
 
Yeah, that's the one
But I see that Google seems to prefer a class-based functor in the Chromium source
 
That's what that is (well, it's a class template, not a class, but that just means less repetitive code).
 
Here's the example from the Chromium source: google.com/codesearch/p?hl=en#OAMlx_jo-ck/src/chrome_frame/…
 
That's exactly the same form as what I posted.
 
Hm, I must be thinking of structs and classes in the wrong way.
 
7:12 AM
They are the same thing.
A struct is the same thing as a class except that its members and bases are public by default, whereas in a class they are private.
 
huh. That's a good thing to know
 
It is.
 
So the decision to use struct vs class in a functor just comes down to personal preference then?
 
The other design decision that I've been thinking about is how my methods should expect arguments to be passed - that is, by const &MyClass or const MyClass*
 
7:21 AM
It depends.
I don't use any raw pointers in application code that I write.
References have the enormously useful benefit that in a correct program they cannot be null.
 
Ah, now that's a design decision I could get behind (coming from a Java background)
But doesn't the new operator throw a wrench into things, since it returns a pointer?
 
Not really.
26
A: What is the philosophy of managing memory in C++ ??

James McNellis What is the core driving design of memory management ? In almost all cases, you should use automatic resource management. Basically: Wherever it is practical to do so, prefer creating objects with automatic storage duration (that is, on the stack, or function-local) Whenever you must use ...

My last hobby project (a partial implementation of the C and C++ preprocessors) had exactly zero new expressions (not including any that are in the standard library code).
The less explicit dynamic allocation you do, the better.
 
That sounds really elegant. I guess I need to have a close look at vector and scoped_ptr
I figured that I won't need to dive into any STL, TR1, or Boost in a little practice project, but more and more, I'm seeing that there's no point trying to avoid good stuff.
Thanks James, you're a hero!
 
No problem.
In my opinion, it's probably better to learn the language top-down, starting off with the STL, the std::string library, exceptions, and other high-level pieces of the language. That way, you learn how to write correct C++ code from the beginning and later you can dig in and see how things work under the hood.
2
 
7:39 AM
@James, that's a good philosophy
 
What's up @sbi
 
sbi
@James I'm up, though barely.
:)
 
I know the feeling! :-D
 
sbi
(It seems finally SO has a place to leave arbitrary comments to some users other than in comments. Although this does require the user to have been in chat.)
<yawn>
I need to get out the house and to work. See you from there!
 
No, you won't. <yawn> Time for me to go to bed.
 
7:46 AM
K... time for a break. C u guys later
 
8:06 AM
1
A: c++0x: overloading on lambda arity

Anthony WilliamsA lambda function is a class type with a single function call operator. You can thus detect the arity of that function call operator by taking its address and using overload resolution to select which function to call: #include <iostream> template<typename F,typename R> void do_stuf...

Awesomesauce.
 
user379888
0
Q: problem in coloring in C

fahadI am using graphics.h library to implement the a shutdown button on the display screen.The problem I am facing is that the color function(setfillcolor()) is not working by which I want to color the area between the two circles in red.My compiler is turbo C. void shutdown(void) { set...

 
user379888
@PrasoonSaurav:Can you help me in this question?
 
user379888
Anyone?
 
user379888
8:59 AM
0
Q: problem in coloring in C

fahadI am using graphics.h library to implement the a shutdown button on the display screen.The problem I am facing is that the color function(setfillcolor()) is not working by which I want to color the area between the two circles in red.My compiler is turbo C. void shutdown(void) { set...

 
@sbi oh do you mean i should insert "being" there? i thought that i had that word initially and it was wrong so someone else fixed it. please fix any typos you find. i'm not native english so i likely have many spelling/grammar bugs :)
i think it should be passive-perfect tense or whatever that grammar construct is called :)
 
sbi
9:45 AM
@JohannesSchaublitb I was taught English on the wrong side of the Iron Curtain. I go by guts when forming English sentences. I'm the last to go in and edit someone else's grammar based on my gut feeling. I don't even know which way to put a ready-to-bake-prepared "passive-perfect tense" into the oven, let alone preparing one myself. :)
 
10:25 AM
If you add a pointer to an object to a list and then edit the contents of what it points to somewhere else, not by getting it from the list, it should still be altered if you then got it from the list right? as they should point to the same thing?
 
sbi
@Tony I'm not sure I understand, but remember: A pointer is just a POD, too, only it's one that points at another one. If you copy a pointer, you end up with two pointer variables pointing to the same variable. If you change one to point at another variable, the other one still points to the old variable.
Does that help?
 
10:43 AM
@sbi yes but if you change the contents of what the pointer points to, then both pointers will have that change?
@tina, this is a C++ chat, not a UML chat
 
sbi
@Tony No, the content of the pointers stays the same. The content of the variable the pointers point to, however, changes.
In code: p doesn't change, *p does.
Does that make sense?
 
Hiii everyone. It seems meta guys didn't like my feature request. :)
2
Q: Conversion from CW to non-CW state?

Prasoon SauravThe question is short and simple. Why can't Community Wiki posts(specially questions) be rolled back to non-Wiki state? P.S : Recently my post here was made CW (by mistake I guess) so I was wondering if something like that(conversion from wiki to non-wiki state) could be implemented. Its merely ...

 
@sbi yes makes sense, thx
 
sbi
@PrasoonSaurav It doesn't have a [tag:status-declined] tag yet.
(Damn. Letdown fail again.)
 
@sbi : What do you think about that request? Are you in favour?
 
sbi
10:56 AM
I op-voted it. Since moderators are humans and can make mistakes, they should have the ability to undo them.
 
Hmm exactly.
 
sbi
Mhmm. That seems a good summary of my thoughts on the matter. Shall I post such an answer?
 
Yes sure :)
 
sbi
@Prasoon Done.
 
@sbi : Very nice answer. Up-voted. I wish I could upvote it more than once. :)
 
sbi
12:06 PM
Quiet here today. Everyone's in bed?
 
im in bed, lolo
 
sbi
@Tony Using a laptop, I assume? :)
 
what you up to @sbi ?
haha yes using a laptop
not in bad really though
just kiddin
 
sbi
Um, I was just looking for an excuse to take a break from working...
 
heheh I know how you feel
how long can you code at max in one go?
 
sbi
12:11 PM
Posted an answer to @Prasoon's question on meta, then another meta question of my own, then back to here. Place is still empty. So I asked.
 
oh i see
 
sbi
@Tony That depends on "in one go" means. Do breaks to go to the loo count? (Probably not.) Lunch break? (Probably) Interruption by some co-worker asking something? Me having to ask a co-worker something? ...
 
except for loo break & lunch breaks.... if you were left alone by co workers
 
sbi
I dunno. They never leave me alone!
 
its cause you're so knowledgeable
:)
so Roger Pate has been deleted...
:(
 
sbi
12:21 PM
@Tony No, but good software is a very collaborative effort. It needs lot of communication.
@Tony Yeah, I noticed. Still don't get why.
Why do you need to actually kill your account, as opposed to not logging in for a while?
 
@sbi maybe he was addicted to SO
 
sbi
12:38 PM
@Tony Once, somebody who knows about this told me that most suicide attempts actually aren't done to be dead, but to get attention to the problem leading to the decision. Killing your account instead of simply abandoning reminds me of that.
 
sure, so what is the problem that got him to leave? does anybody know?
is it the N00bs that ask to many silly ungrounded questions.
 
12:58 PM
@JamesMcNellis No, a FAQ that main always returns int
 
sbi
@Tony I think he first mentioned it here: chat.stackoverflow.com/transcript/10?m=109893#109893
(Sorry, took me a while to dig this out.)
Oh, and you might be able to ask him in person:
Nov 13 at 20:11, by Roger Pate
you can find me on efnet and freenode
 
prob not under the same name...
 
 
2 hours later…
3:07 PM
@FredOverflow Oh... :-P No, we don't have one of those. However, (a) that question is rarely asked directly, (b) that is rarely the issue-causing problem in the OP's code, and (c) it's easier to just type out "main returns int" than it is to hunt down another question.
I dunno; maybe such a question would be useful... it seems a bit trivial though
 
3:36 PM
Good morning fellow typists.
 
3:57 PM
greetings humans
 
greetings
 
Humans and typists. Finger sportsmen, too. Men of intellect and of warm chairs. Men with a vision, men with a dream!
2
 
 
1 hour later…
5:12 PM
0
Q: What is the proper signature of main?

FredOverflowWhat is the proper signature of the main function in C++? What is the correct return type, and what does it mean to return a value from main? What are the allowed parameter types, and what are their meanings? Is this system-specific? Have those rules changed over time? What happens if I violate t...

lol I'm being accused of asking homework question :)
twice :)
 
sbi
@Fred I'm with James on this. It's questionable whether this was really necessary.
 
@sbi Let the community decide :)
At least it gives us insight into the question: "What happens if one posts a FAQ without answering it immediately?" :-)
 
5:31 PM
@James I removed my comment about the array, you can now remove your comment about my comment if you want ;)
great answer btw
@James: awesome answer!
 
Where did Pate go?
 
@GMan Into the void, apparently. (Which is not a legal return type of main, btw.)
 
:[
That's what I get for leaving chat , I miss all the big stuff.
 
We need a way to create FAQs that are locked without being closed
Like "sticky posts" in forums
 
@sbi: I don't know what the process is for merging questions. Fred's is better phrased for a FAQ entry. I agree that they should be merged, but I don't know which should be merged into which.
 
5:47 PM
@JamesMcNellis The "duplicate" is heavily focused on the constness of the strings. I wouldn't merge them, but that's just my opinion...
 
Well, I'll let you guys deal with the logistics.
I'm logging off for the day so I can be productive!
 
@JamesMcNellis How about explicitly stating that void main() is illegal? Or would that be redundant?
 
@Fred: Probably a good idea, since I see that all the time
Even in books
 
@JohnDibling "even in books" yes, sadly :(
 
@FredOverflow: I want to tweak the question over lunch when I can take a look at the standard and see if I missed any important details. I'll add that in there then.
Adding a note about void main(void) is definitely a good idea.
 
5:55 PM
@JamesMcNellis great, looking forward to it!
 
Ok, now I'm really going to go do some work.
 
6:17 PM
@Fred: I can't get range-based for to work with MSVC 10. Do you know if it workes there?
 
@JohnDibling There is no support for range based for in MSVC 10 yet.
 
ok thx
i guess i need to go to the effort of getting g++ on my new machine...
 
sbi
6:50 PM
@James @Fred @John I didn't think we could have avoided this being closed (and I do see some justification in it), so I lean towards making the best of this. I don't see a problem with rephrasing the other question to make it fit for a good FAQ entry. In fact, hijacking "real" questions is what I prefer for FAQ entries.
 
I think I agree with Fred though that the so-called original is more concerned with the qualification of the parameters to main than with the main function itself.
 
sbi
Maybe you should have spoken up there when the dupe was first mentioned?
 
@sbi Is it really closed? Seems open to me...
 
sbi
@Fred No, it's still open, but it has four votes already. Might be a close shave.
 
@sbi Well, we could always vote to reopen in case it gets closed (and if we want that)
 
sbi
7:08 PM
@Fred Of course, we could. But I feel like this FAQ idea has taken a lot of heat recently, because people accusing us of reaping rep by it, voting to close, etc. Rather than spending our energy on close/open wars, let's spend it on finding real questions that are out there, and make them up to be good FAQ entries.
 
@sbi Well, at least the rep reaping argument wasn't raised in my question.
And I don't feel too bad with gaining 4 upvotes on my question :)
 
sbi
@FredOverflow Yes, but should we continue with one of us asking a question and the others chiming in with perfect answers that are up-voted and accepted, we'll have the "FAQ cabal" tag attached to us in no time and be stamped "rep reapers" nonetheless.
 
I'm a little surprised though that nobody seems to care for my latest question :)
@sbi I really don't get it. What's wrong with receiving upvotes for a good answer? I think James should be rewarded for his effort.
 
sbi
(And between us of the FAQ cabal, that's easily the four up-votes you had. Might have been no one else up-voting this.)
 
@FredOverflow what is latest q?
 
7:13 PM
0
Q: Forward headers for STL containers

FredOverflowThe header <iostream> has a companion <iosfwd> which is sufficient if I only need pointers or references to streams. The latter is a common scenario when overloading operator<<. Is there such a header for the STL containers? I want to define a couple of functions that take refe...

 
sbi
@FredOverflow There's nothing wrong IMO. That doesn't prevent heated discussions, though.
 
@FredOverflow Oh, well. There's <iosfwd> and that's that. sorry.
 
@AlfPSteinbach :-(
 
@FredOverflow OTOH., note that e.g. the STL algorithms etc. are "compatible" with std::vector etc. without any dependency, just by using templated iterator types.
 
@AlfPSteinbach Yes, but I really need the vector type itself.
0
Q: Detect the existence of types

FredOverflowSFINAE allows us to detect if a type has certain data members or member functions. Can it also be used to detect if a type exists at all? Background: I want to know whether <vector> was included or not.

Any takers? :)
 
7:21 PM
@FredOverflow I don't feel too bad either, having earned no rep from upvotes for that answer :-)
 
@FredOverflow on the positive side, don't think premature optimization. build time is probably not a problem. on other side of coin, consider that there's not a single std::vector<T>, there's the infinite family std::vector<T,CustomAllocator>, if I recall correctly...
 
@sbi Personally, I wouldn't mind making most of the C++ FAQ questions CW.
 
sbi
@JamesMcNellis Neither would I. Unfortunately, @Prasoon is very fixated at the idea. I think his eagerness about it harmed his case more than anything else.
But that's easy to say for us, who've been here for much longer than him, know our way around better, and have more confidence in the rep we've gained.
@Fred BTW, if you vote-up James comment disputing that your question is a dupe, that will be the second up-vote and lift it above the viewing threshold. That might prevent the fifth close-vote.
I though you'd be interested. :)
 
7:45 PM
@sbi Good idea, thx
13
A: Does "std::size_t" make sense in C++?

Johannes Schaub - litbThere seems to be confusion among the stackoverflow crowd concerning this ::size_t is defined in the backward compatibility header stddef.h . It's been part of ANSI/ISO C and ISO C++ since their very beginning. Every C++ implementation has to ship with stddef.h (compatibility) and cstddef where ...

Why isn't this the accepted answer??
 
00:00 - 20:0020:00 - 00:00

« first day (32 days earlier)      last day (4909 days later) »