« first day (248 days earlier)      last day (4716 days later) » 

Xeo
5:20 AM
wtf... why is my static member char not getting initialized until I actually instantiate an object? -___-
 
@Xeo code, please
 
Xeo
template<class D>
char register_(){
    return D::get_dummy(); // static function
}

template<class D>
struct Foo{
    static char const dummy;
};

template<class D>
char const Foo<D>::dummy = register_<D>();

struct Bar
    : Foo<Bar>
{
};
shouldn't this automagically call register_ if Foo is instantiated for any type?
Or have I some kind of misconception about static member variables? oO
 
Does get_dummy return a reference to a local static object?
Oh wait, shouldn't matter.
 
Xeo
get_dummy isn't even there in Bar
 
Make it a proper SO question.
 
Xeo
5:33 AM
:|
 
What happens if you replace static char const dummy; with enum { dummy = register_<D>() }; (and remove the previous definition outside the class template)?
 
Xeo
> error C2057: expected constant expression
 
Oh wait, then it's not a char anymore...
 
Xeo
constexpr want..
 
Can I see get_dummy?
 
Xeo
5:37 AM
it's not there xD
I don't even get a linker error
or compiler error
 
What do you mean, it's not there?
 
Xeo
What I pasted above is all I have
 
Ah, so you want an error, but the program compiles?
 
Xeo
If I got an error, I'd at least be sure that the char gets initialized...
 
Funny, this is what g++ says about line 12:
internal compiler error: Segmentation fault
Please make this a proper SO question, now I'm curious :)
 
Xeo
5:39 AM
@FredOverflow Ideone uses g++, no error
 
Which version? I use 4.6.0
 
Xeo
4.5.1
for C++0x, 4.3.4 for C++03
 
@Xeo What exactly is the purpose of this convoluted code, if I may ask?
 
Xeo
Automatic registration of some classes
8
Q: C++ Static member initalization (template fun inside)

Mr. Mr. For static member initialization I use a nested helper struct, which works fine for non templated classes. However, if the enclosing class is parameterized by a template, the nested initialization class is not instantiated, if the helper object is not accessed in the main code. For illustration...

> in particular, the initialization (and any associated side-effects) of a static data member does not occur unless the static data member is itself used in a way that requires the definition of the static data member to exist.
meh.
 
Ah, there's our solution. I thought that only applied to class template member functions.
 
Xeo
5:46 AM
Me too.
Damn, so whoever derives from my Foo needs to explicitly reference the dummy... that sucks.
 
Couldn't the constructor make a dummy usage of the dummy? :)
 
Xeo
struct BitmapLoader
    : eve::resources::LoaderBase<BitmapLoader, SDL_Surface>
{
    SDL_Surface* do_load(std::string path){
        return SDL_LoadBMP(path.c_str());
    }

    void do_unload(SDL_Surface* res){
        SDL_FreeSurface(res);
    }

    static std::string extension(){ return "bmp"; }
};
This is all one should have to do
(the extension method is the get_dummy)
 
template<class D>
struct Foo
{
    Foo()
    {
        (void) dummy;
    }

    static char const dummy;
};
 
Xeo
hm
 
Would that work? Can't test here, internal compiler error still :)
Or are Foo structs not instantiated?
Anyway, gotta take a shower.
 
Xeo
5:50 AM
It shouldn't need Foo to be instantiated. :/
Well, there will be an instance... but that will be made with the register_ function... and if that doesn't get called..
 
Xeo
6:01 AM
0
Q: How to force a static member to be initialized?

XeoConsider this example code: template<class D> char register_(){ return D::get_dummy(); // static function } template<class D> struct Foo{ static char const dummy; }; template<class D> char const Foo<D>::dummy = register_<D>(); struct Bar : Foo<Bar&...

 
6:11 AM
@Xeo Does this work?
template<class D>
struct Foo
{
    char non_static_dummy = dummy;
    static char const dummy;
};
 
Xeo
@FredOverflow Isn't that initialization c++0x?
 
right
 
Xeo
And I think that still falls under the same rules - until I instantiate that dummy, I won't have any instances. :| Which doesn't make the dummy needed
HOLY MOLY! I think I found a way
 
Ok, I'll ask it. How?
 
Xeo
ugly, but works
Though I'd rather not have the derived type have to do that...
 
6:19 AM
I think you meant this: ideone.com/3jW5v
 
Xeo
eh?
no, I do not. dummy won't be initialized there
 
Ok, then what's get_dummy for in your example?
All it does is cause compilation to fail.
 
Xeo
it's there to make the compiler error, as a proof that register_ was invoked
remove the get_dummy from Bar in your code
will still compile just fine
 
I'm not sure a compilation error is proof.
But it runs.
 
Xeo
Pff standard output....
 
@MartinhoFernandes that would be a recursive definition (sorry for the pings)
 
Xeo
@StackedCrooked No, why would it?
 
@StackedCrooked I wish desktop notifications wouldn't pop up on edits :( Hahahah, kidding.
 
Xeo
@MartinhoFernandes Oooh. I see now what you did there. :( Sorry, but yeah, that would work too. Totally overlooked that you changed the 42 to dummy.
 
@Xeo it eventually resolves to dummy = dummy;
 
6:30 AM
Is it UB?
 
Xeo
@StackedCrooked Yeah, dummy gets initialized to its uninitialized state
 
@Xeo (void)dummy; what does the (void) do here?
 
Xeo
@StackedCrooked voids the statement, so no warning gets emitted
 
Cool, I can use that.
@MartinhoFernandes that must be fake
 
Yes, it is.
(pay attention to the upper right and left corners)
> Jointly developed by Apple and Kraft Foods, Apple Kool-Aid releases a chemical that disrupts synapse activity in the cerebral cortex — in effect, creating a biological distortion field. Just four ounces of the product produces docile, easily-led subjects within four minutes of ingestion.
 
7:24 AM
"beware of right arrow - it's an L2 cache miss operator"
 
7:39 AM
anyone around atm?
 
sigh, learning and wrangling with MFC is a bit painful after delving into WPF
 
sbi
@Eric_H No. (SCNR)
 
well, drat
 
sbi
@Eric_H MFC? I'm not here!
6
 
7:41 AM
hahahaa
I truly understand that reaction
it really is just... ugly
 
sbi
@Eric_H That's not enough. You ought to live it. :)
 
@sbi no thank you. I hammered long enough to get to refactor crappy outsourced code, then I was told it had to run both in CGI and with a c++ GUI wrapped around it
I'm living it enough at the moment, thank you
but yeah, no tutorials around that actually have more than a superficial example of MDI dev
thus I'm waiting with baited breath for someone to answer my question
s/superficial/trivial
well, it's bedtime. I hope it's not poor etiquette to link to my question here: stackoverflow.com/questions/6421885/…
 
8:19 AM
Mornin
 
 
3 hours later…
sbi
11:10 AM
2
Q: Learning the nuances of a language (C++)

prelicSo I'm a recent college graduate, and I really enjoy working in C++; I worked with it a lot in school, and would like to pursue a career writing in C or C++. The problem I'm having is that I'm trying to learn the nuances of C++. I'm not talking about the basics, or even advanced concepts like tem...

 
(a == 0 ? a : b) = (y < 0 ? 10 : 20);
 
@sbi I'm amazed no one else mentioned the standard. That seems to be exactly the kind of thing the OP wants.
On a totally unrelated note, I hate databases.
 
0
Q: Organize includes

Default Is there some preferred way to organize ones include directives? Is it better to include the files you need in the .cpp file instead of the .h file? Are the translation units affected somehow? How about if I need it in both the .h file and .cpp file, should I just include it in the .h file?...

I remember a couple of years ago, my teacher always added the includes in the .cpp file.. But I really can't remember why..
 
11:26 AM
> ... but doing so may result in unpredictable behavior. Do you wish to try to resume this virtual machine?
Hmmm...
 
Hello everyone
I am new here
 
Welcome.
 
Is this chartroom for advanced c++ discussion?
 
if you want it to be
 
This is a chartroom, yes.
Ask us your most advanced c++ question ever.
and @MartinhoFernandes will gladly answer it.
 
11:34 AM
haha
 
Hi all
Again asking a wrong question at wrong place. Sorry. What is the best book for learning Java ? I have seen the thread voted "Effective Java" as the top. I saw a few contents of it. It is discussed concepts in terms of items like the way "Effective STL". Is the book completely for a noob or there is another one ? Thanks.
Java chat room isn't very active one.
 
@MartinhoFernandes will answer in a second
or so I heard.
 
What's going on here?
 
12:03 PM
29 mins ago, by Ólafur Waage
and @MartinhoFernandes will gladly answer it.
18 mins ago, by Default
@MartinhoFernandes will answer in a second
Where did this idea come from?
 
from @ÓlafurWaage
 
sbi
@MartinhoFernandes Actually, some did mention the standard.
48 mins ago, by Martinho Fernandes
On a totally unrelated note, I hate databases.
@MartinhoFernandes My hate for databases is only eclipsed by my hate for web programming. Unfortunately, these two together lock me out of 80% of the job market.
 
what's wrong with databases?
 
Xeo
Hm. Now I've written a (currently) small resource manager for my game and used the new keyword exactly once in the source for it.
 
sbi
@user635064 I don't know whether this room was originally created with C++ discussions in mind, but the current crowd prefers to use it leisurely, talking about sex, religion, comics, and whatnot, and discusses C++ mainly only whenever @Johannes appears and is not in the mood of teasing us. And that's rare.
 
Xeo
12:09 PM
@sbi We only talk 'bout C++ when we get distracted.
 
@user635064 hmm?
 
sbi
That reminds me of that guy who is searching under the streetlight. When a policeman asks him he says he's lost his key and searches it rather desperately. So the policeman asks whether he knows where he's lost the key, and the guy points to a dark spot half a block down, where to consecutive street lights are defect. The policeman raises an eyebrow, to which the guy answers that he searches here, rather than there, because it's way too dark to see the key over there anyway.
Asking about Java here, because the Java room is empty is about as useful as that.
 
@user635064 - ?
 
That's not a nice way to talk here.
 
Nice? merely point out my observations
pointing*
 
sbi
12:13 PM
@Xeo Actually this seems to be a nice summary. :)
 
And how did you come to such conclusions @user635064 ?
 
sbi
@user635064 Did they introduce a new badge for getting flagged within an hour of entering the chat for the first time?
 
Sure buddy.
 
do you know who I am?
 
sbi
Mhmm. How does one call a mod here?
 
12:15 PM
We know who Bjarne is, who you are? Nope.
 
@sbi - Good one. But I thought that some of you guys might even be proficient in Java also. Or might at one point of time came across it. Just tried my luck :)
 
what mod? what have i done wrong?
 
@user635064 - You have to understand that many of the professionals are spending their time to help us. They are extremely far advanced in C++ knowledge than what you are thinking of. So think twice.
 
im sorry, i will be quiet now. please forgive me and don't ban me and call mod on me. i just felt like trolling for little bit, but i will be quiet now.
 
sbi
@user635064 Nope. Bjarne is Bjarne here:
@user635064 See, and now I feel like plonking you a bit. HAND.
 
12:21 PM
plonking? :)
 
@user635064 trolls are not welcome.
 
that was really a word! never heard of
 
@user635064 watch it. My hello world apps are second to none!
 
sbi
@Default I grew up on Usenet.
 
haha
@sbi I thought you would be a mod, considering you have almost 50k rep. or is it only the <diamond> users who are mods?
 
sbi
12:31 PM
@Default I'm a room owner, and I think >10k rep gives you the (questionable) "privilege" of getting to vote on other people's offensive flags, and maybe a few others. Other than that, I have no special rights.
Oh, wait.
Mhmm. I wonder whether there's some merit to grant a user explicit read access, when everybody has write access. Well, we'll see. Anyway, that is something I can do as an owner.
But I suppose short of locking down this room (as the Android room is, IIRC), this won't help.
Oh well, he's the first such asshole I've seen here.
 
First and hopefully the last.
 
@sbi you mean the "privilege" of being annoyed by seeing other rooms spam :)
 
Xeo
@Raynos Huh, are you saying @Johannes is not welcome here?
 
@Xeo what?
 
Xeo
@sbi lol, 1 answer, 103 upvotes
@Raynos @Johannes is known for trolling around here. :)
 
12:56 PM
ahoj
 
Xeo
1:20 PM
Hm. What would be the best way to erase from a std::unordered_map?
 
sbi
@Xeo std::unordered_map::erase()?
 
What's with the flags?
 
Xeo
@sbi Hm, isn't it internally a vector and as such pretty inefficient to erase?
 
sbi
@CatPlusPlus They rae flagging in the wind, I suppose.
 
@Xeo flag the item to be erased and do a cleanup once in a while
 
Xeo
1:34 PM
Ah, no, it's efficient after all. The vector only hosts the buckets, and when erasing an element, it will just remove it from that bucket
 
sbi
@Xeo I dunno, I never played with std::unordered_map. However, I always advice to first write correct, easily readable, and maintainable code. And IMO for erasing elements from a STL container the obvious solution would be to call erase(). If that's too slow (which you'll find out only through profiling), you can always dirten this up by something clever that's faster.
 
Xeo
while the buckets themselves are lists
 
@sbi aye, always write the naive solution 1st
 
Xeo
I love diving in the standard headers.
 
then add the eccentric behavior
 
sbi
1:36 PM
@ÓlafurWaage Really, I wouldn't call it "naive" to call erase() for erasing.
 
Basic perhaps.
 
template meta functions are CRAZY
 
Xeo
@knittl No, they are sweeeeeeet. :)
 
crazily sweet
 
yellow
Can any of you help me do something that /should/ be fantastically easy?
ie, Get the current time in milliseconds?
 
1:46 PM
which OS?
 
unix
struct timeval time;
struct timezone timez;
gettimeofday(&time, &timez);
Gives me seconds .... and microseconds? I can't actually figure out how to get milliseconds from this!
I'm so bad at C++
 
milliseconds = microseconds/1000
 
you can look at boost if you want?
 
I thought it was that easy too - But that thats giving me 4000 milliseconds... and 9 seconds for the same operation.
Doing this on Android - stuck with the tools i've got I'm afraid and boost ain't one of em
 
i thought android was java
 
1:50 PM
It is
Apart from the native bits
time.tv_usec/1000 gives me 503.000000
 
@Graeme you want the microseconds from 1st January 1970 or from 00:00:00:0001 today?
 
Arg!
Don't mind - I'm doing it before and after a function. I'm profiling a certain functions speed.
 
then you should use a timer
what OS are you using?
 
he's on android
 
google "Android Timer"?
 
1:53 PM
Is it really so hard to get a millisecond value? I find it really hard to understand why every single thing in c++ is just so drastically difficult to do in comparison to other languages
 
constructing an object is pretty easy I believe.
 
@Graeme It isn't.
 
I'm finding it very very difficult.
 
our troll is back
 
It's seconds + microseconds/1000.
 
1:57 PM
@sbi ready with the plonking? :)
 
sbi
@Default Huh?
 
@Martinho What is?
 
The time in milliseconds.
 
@sbi wasn't it 635064 you were going to plonk?
 

« first day (248 days earlier)      last day (4716 days later) »