« first day (10 days earlier)      last day (5158 days later) » 

08:01
Can I paste a 40 line snippit here?
Ah well
void MyClass::CreateInstance()
{
assert(!sInstance);
sInstance = new MyClass();
sInstance->init();
}

void MyClass::DestroyInstance()
{
if (sInstance)
{
delete sInstance;
sInstance = 0;
}
}

MyClass & MyClass::Instance()
{
assert(sInstance);
return *sInstance;
}

MyClass::MyClass()
{
}


MyClass::~MyClass()
{
EthernetSessionPool::DestroyInstance();
Clock::NtpTime::DestroyInstance();
Ipv6Address::Finalize();
}

void MyClass::init()
{
Ipv6Address::Initialize();
Clock::NtpTime::CreateInstance();
EthernetSessionPool::CreateInstance();
Maybe, never seen it tried. You can use codepad.org
Seems to work fine with embedded scrollbar
Ah, that's good on the chats part. (Bravo chat team!)
So MyClass is non-copyable. This is my modified 'safe' version.
I don't know if this is the usual solution however.
Ok. The calls to those functions need to be wrapped.
You need a class that, in its constructor, calls Ipv6Address::Initialize(); (for example), and in its destructor calls Ipv6Address::Finalize();.
Then you make that a member, and voila.
08:04
These look like manually-managed singletons
I had something like that. As an inner class.
brb
Members that were initialized have their destructors called automatically. So you use three resources (ok) and those classes manage a single resource each (also ok).
What you have is indeed bad: managing multiple resources.
(And an init function is code smell.)
And why do you use Ipv6Address::Initialize() and Ipv6Address::Finalize() instead of using Ipv6Address's constructors and destructors?
(same for the two other classes)
08:20
In what way " "uint64" preferred to "int" in declaring?
In what way " "uint64" preferred to "int" in declaring?
uint64 will be 64 bits, so you know the range, while int is the "normal" int type, typically 32-bits but not guaranteed
And typical -> Modern desktop computer
@Tomaka17: the Initialize and Finizalize are static functions and allocate a static resource to be used by all instances.
So I need to call them once at startup and shutdown. By the way that's legacy code I'm working with and I don't have the freedom/time to redesign it all :$
So then you can't just willy nilly call Init and Final every time you make and destroy an instance, can you?
@Gman Thanks. What's the meaning of this one: static const uint64 UnitOne = 100000000ULL;
Or is it properly reference counted somehow?
08:24
especiallly 1000...ULL
@GMan, that would probably work as well.
@neversaint It's just a constant. ULL is a suffix and gives the literal, in this case, the type unsigned long long.
unsigned long long is guaranteed to have at least 64-bits of storage.
Basically, it makes a constant that won't be truncated to anything less than 64 bits, then sticks it in a 64 variable.
I wish this chat can have a upvote to your very educational/helpful reply
08:27
There is a "favorite" feature, but I don't really understand its purpose
@Tomaka17 but it doesn't increase the reputation
It's okay. Like James said, "See; I don't like this chat already. If you had asked that on Stack Overflow, I'd have gotten at least ten rep per letter of that first answer ;-)"
reading manual is more educational than a chat
I think I found a bug in MVSC++ 2010
When I write std::make_tuple in a lambda, I get a compilation error "can't find make_tuple"
Intellisense recognizes it, and if I write it outside of the lambda it works too
@Tomaka17 ::std::make_tuple ?
08:30
Doesn't work either :(
Ok that's when I use make_tuple in a lambda in a constructor's initializing list
@Tomaka17 can you show a minimal code to reproduce it?
Error -> MyObject::MyObject : _handler([]() { return std::make_tuple(5, 2); }) {}
I didn't test this minimal code, wait a minute
That should be fine. Granted, VS is very buggy w.r.t 0x.
`class Foo {
Foo() : handler([]() { return ::std::make_tuple(5, 3); }) {}

std::function<std::tuple<int,int> ()> handler;
};`
Stupid question: But how do I ask a question and tag it as Community Wiki?
08:34
Hum how do you make that ` work around multiline code ?
@Martin: I think CW was removed. Heard it from a friend who heard it from a friend, etc.
Time to search meta/blog.
@Abyx: Are you going to report that bug or something? (since you asked for a minimal code)
@Tomaka17
Oops. When you post, look to the right past send and upload, and you'll see a "fixed font" toggle.
Click it to make the entire message fixed font.
class Foo {
Foo() : handler([]() { return ::std::make_tuple(5, 3); }) {}

std::function<std::tuple<int,int> ()> handler;
};
@Tomaka17 i just want to look at it =)
As far as I can tell, it's all or nothing when it comes to fixed-font formatting.
08:37
@GMan: Ok thanks
And how do you write multiline text without copy-pasting ? That's another thing I didn't find in the FAQ
foo
bar
Shift +
Return/Enter
user379888
hello all
@Tomaka17 Shift+Enter.
Oh ok, I tried Ctrl + Enter last time and it didn't work
It's easy to forget, though, so I copy-paste anyway. Also, the shortcut to fixed-font is indentation by four spaces. But like I said, it seems to be all or nothing. So you can't say "Here's my code:" and within the same message get fixed-formatting, unless the whole thing is. Hope that changes.
Hello @fahad
sat
sat
08:39
Hi Guys...I am facing one scenario which is leading to error .Scenario is My Process A ...binds a library L which has a static variable S..Now after some time Process A loads a DLL D, which also used same Static Library L.
user379888
@GMan any idea about this certification?microsoft.com/learning/en/us/…
sat
sat
So what will be state of static variable S after loading DLL
@fahad Huh? Dunno what that is.
@sat IIRC, all major Os's reference count shared libraries. So your process will have only one copy of L loaded, so the state of S should be what is what prior to loading.
user379888
I was wondering if I should do this certification course or not...
But it sounds like you have motivation for asking, so instead of asking theoretical questions, why don't you just ask about your real problem? On SO, preferably.
@fahad Up to you.
sat
sat
08:43
@ GMan thanks ..My problem is that when DLL try to access Static variable it do not get the same which my Process A is having...i.e. state is different
user379888
I have done C now I am confused between doing C++ or C#,what to do first
sat
sat
OS is Windows, C++ , VC98 :(
VC98? D:
Well, this this isn't a minor question please ask it on the main site.
Include as much detail as you can.
sat
sat
@Gman Thanks ....and Thanks to Stackoverflow for this wonderful initiative (chat)
user379888
@GMan: how can I know how much memory can a address occupy ? like 100f ffff?
08:47
@MartinYork See meta.stackoverflow.com/questions/392/… and meta.stackoverflow.com/questions/67039/… Didn't get to read it (heading to bed), but I guess those contain the rationale.
@fahad What do you mean? You can use sizeof(void*) or whatever pointer to see how big it is, but pointer representation is implementation-defined.
user379888
@GMan:That was asked theratically in an examination
It's totally outside of C++ to try and care how much memory you can address, and only has rudimentary means of finding out the potential range via the size. That kind of stuff is dependent on the implementation, not C++.
@fahad there is no way to get it
user379888
@abyx:Is there something like ints are always stored on even locations in the memory?
on aligned locations %)
08:52
I'm off to bed now, night.
user379888
@GMan:Good night
user379888
@Abyx:Aligned locations?What are those?
even heap manager doesn't know size of allocated memory, it only knows how much memory to free on free() call
so you can't get allocated memory size by it's pointer
anyway it's really platform-scecific
user379888
@abyx:so there is no way we can get the sizeof dynamically allocated memory?
@fahad yes
user379888
08:58
@I am starting C++ ,can you guide me nice book to start with?C++ for dummies?
250
Q: The Definitive C++ Book Guide and List

grepsedawkProvide QUALITY books and an approximate skill level. Add a short blurb/description about each book that you have personally read/benefited from. Feel free to debate quality, headings, etc. Books that meet the criteria will be added to the list. Note: FAQs and other resources can be found in the...

hi...
I'm looking for a sample win32 GDI code to save a HICON into a .ico file ....
user379888
@Tomaka17:I find many of those recommended by SO very hard to understand
If you write x = new char[3], heap manager will allocate 16 bytes (or 8, or 4) and will remember that it allocated 16 bytes, so on delete x it will free 16 bytes. And nowhere will be information that actual size of *x is 3.
user379888
@Abyx:thats a weird memory allocation,never saw that before
user379888
09:03
x=malloc(sizeof(char)*3);
@fahad malloc and free are the same as new and delete
user379888
@Abyx:only I and the compilers knows the size of x then
@fahad if it's const. But for malloc(rand()) - noone.
can any one tell me the best search engine in c++ ??
user379888
@rajes
user379888
09:09
@rajesh: google code search
@fa
user379888
Huh!
@fahad i am asking about the already implemented one which is easy to use and friendly
@rajesh written in c++ ? and search what?
@Abyx the web
09:31
How do you "make" a specific file?
generally if we type make it will compile all the files, but if you only edit 1 file it will be too time consuming to "make all"
make should only compile the files that have changed since the last build
If you want to compile a precise file, you can write make myfile.o for example
hmm ok
More precisely, if the last modification time of a source file was after the last modification time of the compiled file (the .o) then it is recompiled, otherwise it isn't
 
2 hours later…
11:10
hello guys, does anyone know a decision tree implementation(with continuous attributes) for c++, easy to install with such feature as saving its structure to file and loading from file?
Hello
@Anton got me...
@spoulson
ah damnit.
anyway, eh?
Edit :) (edited)
yay, awsum :)
Never need to use a decision tree... can't recommend one
11:16
its like graveyard in here, noone uses c++ anymore, did i miss smth?)
Yeah. I brought up DirectX at one point and seemed like I got a lot of weird looks.
Seems to be mostly Unix-based C++ coders here
fortunately mine one applies to both unix and windows. found one good lib, but its install guide is like "cd...make...make install", nothing about the existence of windows programmers lol
btw, are you using VS?
Is there a good way to isolate memory leaks? i have a problem described here: stackoverflow.com/questions/4013045/… and cant determine what exact line overwrites memory or what the hell happens in there.
Hmm, I hate memory leaks
I don't know what to recommend for you. I mean, you can probably enable some kind of memory allocation debugging.
Or shift to boost smart pointers
11:38
@Anton I didn't read your code but you should use assertions a bit everywhere, they will help you determine what's wrong
That, too. I've been in the habit of putting ASSERT() on everything.
I only wish that I could ASSERT with the option to show a debugger message and enable a breakpoint.
.NET supports that concept pretty well
What do you mean? My Visual Studio already does that
If `ASSERT(somefunc())`fails, I get a popup showing what line of code it asserted, but only gives me the ability to abort, retry, ignore.
I guess I could jump to that line of code, enable a breakpoint and click Retry.
Seems tedious, tho
And clicking on "Retry" doesn't bring up the debugger?
Can't recall if I tried it, but I didn't expect the debugger to get involved without a manual breakpoint.
11:42
anyone know about where is socket.h in linux gcc
g++ *
I try #include <sys/socket.h> but there's none
@spoulson It does ; clicking on retry will do as if you had paused the execution just before the assertion
@Arman hhi :)
@nXqd, have you work in solaries?
@Arman no.
:-(
11:44
I just begin my coding in linux :P
You know about QT4
?
no :D, I downloaded next week but I don't have time to use it :)
[ school exercises and sickness ]
Oh..!
@Arman how your work going
@Tomaka17 I see. I will have to look closer at that.
11:49
I have just listen about QT4, I will start work on it.
Its looking interesting.
Anybody good with MFC Doc/View model?
@spoulson No, I prefer WTL but still don't make it work in vs 2010
@Arman hey, can I have your free time so we can learn together
12:14
@nXqd why not, I have time.
MFC and WTL now littel bit got old and no more the preference of industries..
Y not win forms and other replacements of MFC and WTL...?
@Usman : google still use WTL for performance :)
@Arman ok , I'll be back, must go to school now .
@Usman I'm working with Direct 3D and prefer to work at C++ level.
@Usman Also learning MFC for fun
@spoulson: Can you bit give hint for what kind of jobs and tasks are performed inn WTL..? I mean what kind of problems addressed and mapped in WTL as told by nXqd that google use WTL there....?
12:32
@Usman Why are you asking me? :confused:
yup my self confused about the usage of WTL...? as nXqd addressed that google use it.. so I got excited to learn and use it myself. As before I was understanding that these are old folks and now MS introduce hell alot new technologies to use and work with.
So wana learn and need to dig into.
12:57
if I have a function foo(int a, char b="b", float c=1) can I call foo(4, f) as well as foo(4, 5.32)?
or in order to pass the float, do I have to have passed the char?
@thecoshman no you cant, parameters order is important
should be foo(int a, char b = 'b', float c = 1)
single quotes for chars
@spoulson thanks for the info, but that's not really the issue I am after here
It will be eventually
@Anton but the order is the same, i'm just wanting to skip over a middle argument, its of a differing type though, can I still not do this? would function overloading be the way to go for this then?
13:00
compiler expects you to pass char as second, you cant pass float. yes, use two different prototypes for foo it will work
@spoulson that was purely an example to ask my question, whilst I am sure one day I will need to know the single quotes should be used char, my question could have been asked with any type
@Anton Thanks dude
Ur welcome.
just noticed the stared posts thing... unsigned long long... aint a long just a long float, so why can we have unsigned long but not unsigned float?
@spoulson: Can you bit give hint for what kind of jobs and tasks are performed inn WTL..? I mean what kind of problems addressed and mapped in WTL as told by nXqd that google use WTL there....?
13:08
@thecoshman long is not a long float. is a type modifier that means integer type by default. there is no such thing as unsigned long with floating point. only 3 types have floating points: float, double, long double. nothing else.
ooooh I see,yes my mistake
Still don't see why I can't have an unsigned floating point, conceptually it makes perfect sense to me
Why would you need that?
I think unsigned integral types exist mainly because it makes bit manipulation easier
If a game monster class has a function take damage, by having it take an unsigned float, I can take decimal damage, and not have to check if it is negative, so that the code is actually increasing the monsters health when it is dealing damage
@thecoshman are you thinking of long doubles?
@thecoshman i think it may be useful, but sad thing is, current machine commands dont support floating points operations with unsigned value. may be because of its representation in the memory. for years of computer science evolution unsigned floats havent born, there must be a reason for it, in my opinion.
@RogerPate "are you thinking of long doubles?" lol sounds weird :D
13:14
@RogerPate yer I was :P
@thecoshman you can use abs(), if you're that paranoic :D you program must work with right values, not allowing to pass negative floats to damage function. So your example is not that good.
@Anton yes I know that I could use abs in the function to check the value is non negative, but If I could use a non negative type, my class will not have to worry about this
but that is just transferring the problem to some where else
14:13
Guys, need ur help. I have two files - Image.h and Image.cpp. when i include Image.h in my main.cpp, everything links right. When i add Image.cpp(which includes Image.h and several windows header files), linker fails with such message: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in libcpmtd.lib(newaop.obj)
oops, nevermind, this one worked well: stackoverflow.com/questions/1146338/…
ah heavens its not working. damn shitty linkage system
You mean: damn shitty microsoft library hell?
yesh. yes i meant. what do i have to do if i have two projects in one solution, one of them is a static library which doesnt need mfc, and the second one uses mfc. What the heck do i have to write in all these millions of parameters for linker?
Zuu
Zuu
15:13
Cant you just build the two projects with different options?
15:27
I think the only file that a .cpp should include is the relevant .h the .h then includes all the other includes that it needs to
Plus I think image is a reserved word in visual studio so you can't make a class of that name... at least vs2010 will not let me.
hello ppl... can anyone please tell me where to get some relevant detailed explanation about oops concept ?? any link anywhere ...
??
@thecoshman A .h file should include all the headers it needs to include. A .cpp file should include all the headers it needs to include. Those two sets of headers may (and probably will) be different.
@JamesMcNellis but the .cpp includes the .h, so all the stuff that is included into the .h is included into the .cpp ain't it?
@thecoshman image is not a reserved word and Visual C++ has no problem compiling a class named image.
@thecoshman Yes, but the .h file should not include anything it doesn't need. It is likely that the implementations of your classes (in the .cpp file) has more dependencies than the declarations of your classes (in the .h file)
@JamesMcNellis Image is though which is how you would type the class name
@JamesMcNellis oh I see what you mean now
15:33
@thecoshman There is no problem with Image either.
@JamesMcNellis In VS2010, if i try to use the project > add lass and call my C++ class Image I get a warning saying that Image is reserved and can't be used
heh. add lass
I wish that button existed.
shh you... ¬_¬
Just write the class in a source file.
15:54
Is there a way to create a variable without a type?
and give it a type later?
I'm trying to make a config parser, and I'm stuck on how to store different types of options in the same struct. pastebin.com/qSZ4X8yT
You can use a stringstream, but this will only work for basic types
The only types I'd use are int, string, char, and float
Store each value in the stringstream, then extract them when you know their type
Or keep it simple and make a union type with a flag indicating which type is represented.
16:03
Personally I think that the easiest way to make a configuration file is to use lua
If you're already familiar with lua I suggest you use it (and if you have the choice of course)
I'm familiar with python, but not lua.
what's this union type?
union is a struct type where all the members share the same space in memory.
union MyUnion { int a; double b; };
MyUnion mu;
mu.a = 1;
mu.b = 3.14;
interesting
So effectively, the address of mu.a and mu.b are the same. Assigning mu.b effectively trashes mu.a.
It's effectively effective.
Note that unions have many restrictions if you don't use basic types
At least for the moment (C++0x will change this)
16:12
I vote for renaming it to C++1x
C++∞
The french wikipedia says "C++1x, anciennement connu sous le nom de C++0x" ie. "C++1x, formerly known as C++0x"
guys, why can this message appear when debugging in VS2008:"Unhandled exception at 0x00000000 in app.exe: 0xC0000005: Access violation reading location 0x00000000." i cant even determine(stack frame is filled with values like 0000000000) on what exact line program tries to read from 0 memory location, and how the hell its even possible?
Stack pointer got trashed
how can i determine what exactly trashed it? is there a way?
One of these days I'm going to find a way to actually use memory at 0x00000000.
16:16
it is possible, if something is mapped there
@Anton: this usually happens when you write too much data in an array, if that helps
@Anton: Well, I suspect a function call got mixed up and landed in a weird spot where an instruction must've messed up the ss and/or esp registers.
I heard of one case where the optimizer assumed a pointer to 0 was null, breaking code that actually wanted to access it
@Tomaka17, what do you mean "too much"? out of range values or wrong indices? Im not sure i get it
wrong indices, for example int a[2]; a[3] = 0;
16:21
@spoulson im not doing something extraordinary with my function calls and array access, why shud ms c++ compiler behave in such manner?
@Anton Can this be replicated?
@Tomaka17 vs usually tells me about out of range indices. i must have mentioned that this happens on some iteration, 144th or so, and iteration is always the same.
Oh that's still your same question as this morning
@Tomaka17 :D yeah. cant get rid of it.
@spoulson sure, i did it many times, always the same result
@spoulson bjarne's 0x faq page gives rationale for keeping the name, which is just a "project codename" anyway
also: "It's been called C++0x for a long time, and I don't see a reason to change that until we have an actual number, like C++11 or C++12. C++1x should be reserved for the immediately following version, which (IIRC) some people hope to have out around 2018 or so." – David Thornley
16:29
Damn I thought it was 2016
Can't wait for concepts and modules :p
@RogerPate That's my suspicion. But I hope it doesn't end up keeping its codename after ratification.
it will; not necessarily a bad thing
at least until everyone transfers to c++11 or so
the [c++0x] tag will get renamed, but I wouldn't change old posts
I mean for the community.
I don't recall C99 taking this much effort to ratify
Though, I didn't follow it closely
I don't recall C99 quickly gaining traction though either.
depending on who you ask, it still hasn't
CPython still targets C90, iirc
16:44
Exactly.
I had just barely started following the committees in 99 (was in high school), and I think that's what spoulson meant: that effort
I think the process has been made much more accessible in the last decade, being just as public but people also not watching
That could be
e.g. they stuck to their compilers and didn't care about the standard
Well it is hard to change standards once you have a large codebase on it
This is why at work I code in .NET 2.0 on Visual Studio 2005. Third party crap just won't work on anything newer.
0
Q: The next next C++

Roger PateIt's entirely too early for speculation on what C++ will be like after C++0x, but idle hands make for wild predictions. What features would you find useful and why? Is there anything in another language that would fit nicely into the state of C++ after 0x? What should be considered for the nex...

why the downvote?
17:24
That's a difficult question... as if you had asked in year 2000 what would C++0x be
IIRC at that time almost everything was single-threaded, there was no way to guess that a <thread> header would come
@Abyx No they aren't.
17:43
4
Q: Setting up a FAQ for the C++ tag

sbiUpfront: I know this is off-topic here, belongs to meta, and should be closed and moved to meta. I post it here nevertheless, so it will get seen by more people who watch the C++ tag. Feel free to move this to meta (I've even tried to already add the discussion tag, although I'm not sure it will ...

Sweet.
Ha ha ha; it's been a while since I saw a meta question get +10 and no close votes on Stack Overflow :-D
Yeah, lol. I'm sure a moderator will move it eventually.
Is there a way to search a vector of structs for a struct with a particular value?
std::find
18:11
clearly a map is better here
Usually. If you insert infrequently, sometimes you can get better performance by sorting the vector, and then using binary_search on it.
I'm using it to store configuration variables
pastebin.com/8aKGhWUg That's how it works at the moment, seems to work well.
Why don't you change

char buffer[1024];
while(cfgFile.getline(buffer, 1024))

To

std::string buffer;
while(std::getline(cfgFile, buffer))

Then you can read any length of line, and don't have a conversion to string later.
hmm, didn't know that was a function in std
thank you :)
np
18:24
can I give you rep in the chat? You've been extremely helpful
No, but thanks.
c++ is a lot easier when i actively try to avoid pointers as much as possible :D
2
I think arrays and pointers are the causes of most of the beginners' questions
That seems to be where most of my issues stem from
@GMan: for sorted vector vs. map it's not so much a matter of "insert frequently" as it is whether you have a mixture of inserting/search, or mostly insert all your data, then do searching. If it's a mix, map will usually win. If it's in phases: 1: insert, 2: sort, 3: search, then a sorted vector will usually win.
18:29
@Bocochoco Then don't use them!
@JerryCoffin Ah, that does specify it better. Thanks.
I'm trying not to! at least until I get to SDL :/
Bias on my part, since I was thinking "max lookup amount", so mix is directly determined by insert frequency.
I don't think im going to be doing anything of that sort, just trying to read variables from a file and use them where appropriate. Probably will only be used once at initial execution.
18:49
21
Q: Setting up a FAQ for the C++ tag

sbiUpfront: I know this is off-topic here, belongs to meta, and should be closed and moved to meta. I post it here nevertheless, so it will get seen by more people who watch the C++ tag. Feel free to move this to meta (I've even tried to already add the discussion tag, although I'm not sure it will ...

Everyone shall read the above, or your C++ sucks.
@GMan there is so much letters, and its has no correlation with my C++
requesting tl;dr
@GMan: Good idea, but I think this is a fault with StackOverflow in general, for all tags. Not just the C++ tag. Moderation in terms of closing stuff as duplicates should have required less points, so such questions could be closed faster.
@MadsElvheim The hope is the later this idea will be applied to all tags, automatically.
I can't wait until I have sufficient rep to do something more than just flag dupes for moderator attention.

« first day (10 days earlier)      last day (5158 days later) »