« first day (352 days earlier)      last day (2501 days later) » 
00:00 - 14:0014:00 - 20:00

2:04 PM
anonymous is just some shit that person made up- Also stop using raw arrays like that, use std::vector for dynamic arrays, and std::array for static arrays.
 
Ven
what, "fixed font"??
am I getting trolled
 
what is the diference between cout and cerr?
 
people told me that cerr is for error messages
 
that only matters when creating command line tools, cout is the normal output possibly piped into the input of another program
 
2:20 PM
:V
 
Ven
sounds correct
 
2:37 PM
is this the best way to create a empty string?
std::string iogs = "";
 
Ven
std::string logs; is the best way
 
std::string iogs; does that too
 
hmm ok!
 
Could anyone tell me that a pure virtual function in c++ can or cannot exist in a non-abstract class???
 
Ven
sorry, iogs
 
2:38 PM
one more question , if the string iogs = "a", and i do this iogs += "b", will iogs = "ab"? correct?
 
nice, ty
 
when a class has a pure virtual function then it is abstract
 
@ChandanPurbia what if you tried to call such a function from an instance if the class was non-abstract?
 
3 messages moved from Lounge<C++>
 
2:42 PM
@ratchetfreak can non-virtual functions exists alongside with pure virtual functions??
 
@ChandanPurbia yes
 
@BartekBanachewicz but pure virtual functions prevents anyone from making its objects, isn't it?
 
im having an error in xutility o.o
 
@ratchetfreak so even though there is a non-virtual function in class alongside a pure-virtual function, we can call the class an abstract class?
 
2:46 PM
@ChandanPurbia that's the definition of a class being abstract
 
i have this error while compiling: '==' no conversion from 'const char *' to 'int'
the error comes from xutility file
annyone help?
 
SSCCE please
 
sscce?
 
@BartekBanachewicz In java if a class is abstract all of its functions has to be pure virtual. That is why I got all confused. Thankyou :)
 
2:48 PM
@ChandanPurbia that's not true
 
@ratchetfreak In java if a class is abstract all of its functions has to be pure virtual. That is why I got all confused. Thankyou :)
 
@ChandanPurbia I don't think that's true either
> An abstract class is a class that is declared abstract—it may or may not include abstract methods.
 
but i dont know how to error happens because it doenst come from my code
 
In Java a class is abstract if you declare it abstract
 
@jeyejow then it most probably comes from improper API use on your part. You're violating someone else's contract.
 
2:49 PM
@jeyejow no, it does come from your code
 
it comes for xutility file, i didnt write code there
 
YOUR CODE IS BROKEN
now, show the code
 
my hole code?
its kinda big :v
 
3 mins ago, by milleniumbug
http://sscce.org/
 
i tried removing the part i added
but still the error
 
2:51 PM
@BartekBanachewicz I was getting confused in interface and abstract class. Thankyou again :)
 
ok ok, but i dont know how to replicate the error cause i dont know were it is comming from
or what is causing ti
 
@ratchetfreak found jt. You are right.... Thankyou :)
 
it*
 
keep removing the code until the issue disappears
 
o.o ok :v
 
2:52 PM
then add that code back in and remove other code
 
the error message should have come with a file and line number
 
omg im such an idiot sometimes
lol
nvm, i found the problem :|
okay, i managed to reduce alot of lines in my code :D
does someone have a link explaining the % you put in the wprintf?
 
3:07 PM
how do i used fopen_s ? it asks for a FILE** and not a FILE* , this is what i tried, it gives error
FILE* pFile;
fopen_s(*pFile,input,"r");
it says it only assepts FILE** and not FILE*
 
fopen_s(&pFile,input,"r");
& is the address of operator
 
ohh ok ill try that :o
so i do this? @ratchetfreak
FILE* pFile;
fopen_s(&pFile,input,"r");
 
@jeyejow don't open files in C++ with fopen
 
lol fopen
 
@BartekBanachewicz i just open it to see if it exists, but what do you recomend?
 
3:08 PM
lol opening to see if it exists
it may be deleted in the meantime between checking and doing something on it
 
what should i do then
 
what are you doing with the file
 
in my program i create a HANDLE and use createfile to make a handle to a file, and then i mess around with it, i read bytes and write bytes to it
 
if CreateFile returns an error, the file doesn't exist
 
yes, but people told me to use fopen to see if the file exists
cause it was faster
 
3:11 PM
they're morons
 
is fopen bad?
 
it forwards to CreateFile
 
not particularly, I'm just laughing at the rationale
 
:O but that makes no sense
createfile is a windows function, no?
 
there are better alternatives than fopen
 
3:12 PM
fopen works in unix
i think
but ok, ill use the createfile, then fopen :O
 
guess what: if you use a portable function and a platform-specific function in the same program, is your program portable?
 
yh, nope ahaha
 
fopen is a C standard library function that is implemented based on whatever is available in the platform (CreateFile in windows and open in linux)
 
one question, if i have for example int main() and inside int main i make a handle and do the createfile thing. if i create a function outside int main that takes a HANDLE as argument, and i call it in int main with the HANDLE that was use in the creatfile, will in that external function be like if i alreaddy used create file with that handle?
or would i need to make annothr handle on that external function?
 
handles are alive until you close them
 
3:16 PM
wait, let me write some code so you understand my question
 
void foo(HANDLE file);

void main(){
    HANDLE f = CreateFile(...);
    foo(f);

}
like that?
 
53 secs ago, by milleniumbug
handles are alive until you close them
 
the file parametere inside foo will be the same as the handle that was created in main
at least for that call
 
int close(HANDLE x)
{
CloseHandle(x);
}

int main()
{
HANDLE f = CreateFile(....)
close(f);
}
@ratchetfreak ohhh, so the code i did wouldnt give me error and would close the handle?
 
3:17 PM
omg thats awsome!
my program will become so short :D thanks!
one question, if i have a function that returns 0 if everything inside it goes correct
and if i want to return, if something goes wrong, the GetLastError() thing
how do i read it from the other side?
if (function() == 0) { nice}
 
assign it to a variable...?
 
if (function() == GetLastError(?????)) { ther error was GetLastError}
ohhhh
 
err = function();
if(err == 0){ nice}
 
also, you could just throw an exception
of course, with all that exception unsafe code that would be risky
 
@ratchetfreak and now it my function does this : return GetLastError()
if (err != 0)
 
3:24 PM
which is why people use std::unique_ptr, std::shared_ptr, std::vector, std::string and so on
 
{ output the return value
how do i output the return value?
ohhh i see
it there a way to output the return value of a function?
 
3:40 PM
no magical way, it is variable like any other, print it if you want
 
but how?
std::cout << function();
?
 
that will work if cout can handle the type of the return value
 
nice nice
one more thing
 
or assign to a variable and output the variable
 
3:43 PM
can i return some text + a number? something like this: return "text"+ 5, how do i do it if it is possible?
 
std::to_string(5)
 
you can return a struct with a string and a number, or combine it into a big string with std::to_string(number)
 
text formatting...
 
ohh so i can have something like std::string x ="hello" and then return std::to_string(x+5)?
 
no quite.. x + std::to_string(5)
 
3:45 PM
hhmmmm ok ill try that!
std::string x = "hello";
	x += std::to_string(GetLastError());
	return x;
this gives me an error
"no suitable converion std::string to int"
 
is your function return type int?
 
oh
i forgot that eheheh
 
hi guys
template<typename D, typename B>
class IsDerivedFromHelper
{
    class No { };
    class Yes { No no[3]; };

    static Yes Test( B* );
    static No Test( ... );
public:
    enum { Is = sizeof(Test(static_cast<D*>(0))) == sizeof(Yes) };

};
why this template helper class should allow to state whether D is derived from B?
and how should Test be implemented?
(it's taken from an interview question)
 
it's your classic old-school SFINAE pattern
 
Test shouldn't be implemented at all, it's never called at runtime
 
3:55 PM
int createx(HANDLE x)
{
	x = CreateFile(...);
}

int main()
{
	HANDLE f;
	createx(f);
	CloseHandle(f);
}
can i do this?
or do i need to return the HANDLE in the create(), so i can close it in int main?
 
Then I don't understand that template
 
Test is overloaded such that if D derives from B it will use the one that returns Yes
 
@jeyejow you need to return it
 
@ratchetfreak oke ty!
 
parameters are copies and don't affect the original variable (unless it's a ref but in your example it isn't)
 
3:57 PM
I think the key is to understand this
static_cast<D*>(0)
so a casting to D is performed
if D is derived from B
 
@user8469759 note the following: Yes and No have different sizes. D* is implicitly convertible to B* only if D derives from B publicly or D is the same as B. static_cast<D*>(0) is the same as static_cast<D*>(nullptr)
 
then D is also B
 
@ratchetfreak how do i return a HANDLE?
 
and in that case the static Yes( B* ) is used
is that correct?
 
HANDLE createx)
{
	HANDLE x = CreateFile(...);
       return x;
}
 
3:58 PM
otherwise it use the No
 
@jeyejow Technically no, you don't need to return it. You could instead pass it by reference: int createex(HANDLE &x) ....
 
@ratchetfreak ohhh oke
 
is it correct so far?
 
@JerryCoffin can you explain how that works? i never did that before
 
have you read an actual C++ book
I suspect you didn't
 
4:00 PM
no :V
 
4260
Q: The Definitive C++ Book Guide and List

grepsedawkThis question attempts to collect the few pearls among the dozens of bad C++ books that are published every year. Unlike many other programming languages, which are often picked up on the go from tutorials found on the Internet, few are able to quickly pick up C++ without studying a well-written...

@user8469759 yes, this is correct
 
ok
one more question
is there a subtle meaning
of the class Yes { No no[3];}
that array
 
note that the reason why No Test( ... ) is called is subtle
 
why is sized for three?
 
they want to make Yes and No different sizes
 
4:01 PM
the static_cast is used to get a D*. Then Test is overloaded so the version that takes B* has a unique size
 
it doesn't really matter why it's 3, could as well be 42
 
thats all it is for
 
what matters is that sizeof(No) != sizeof(Yes)
 
@milleniumbug I got that
I'm just trying to understand how they achieve that
 
because Yes is contains an array of No inside?
 
4:02 PM
so instead of class Yes {No no[3];}; they could have done something like Yes { int var;}
?
 
doesn't this have a weekness that a rogue Test(D*) declaration could throw it off?
 
yes except you have no guarantees about how big is int
 
but it would be different from No
 
or how big an empty class is
 
user: that doesn't guarantee different sizes so no
 
4:03 PM
@user8469759 it potentially could have the same size
 
ah ok
 
@user8469759 and empty class has a non-zero size which may as well be the same as an int's
 
sure
I did not think of that
 
for example typedef int Yes; typedef long No; would be broken on half of the platforms
 
what kind of basics do you think I lack of?
 
4:05 PM
@JerryCoffin different person
 
overload semantics, templates
 
@milleniumbug Oops--did I cross the streams? My apologies.
 
In the C++ programming language, a reference is a simple reference datatype that is less powerful but safer than the pointer type inherited from C. The name C++ reference may cause confusion, as in computer science a reference is a general concept datatype, with pointers and C++ references being specific reference datatype implementations. The definition of a reference in C++ is such that it does not need to exist. It can be implemented as a new name for an existing object (similar to rename keyword in Ada). == Syntax and terminology == The declaration of the form: <Type> & <Name> where <Type>...
like that?
 
@user8469759 Yes, that was what I had in mind, but as @milleniumbug pointed out, it's really just a stupid mistake on my part. My apologies.
 
@ratchetfreak shoudlnt it be like this?
HANDLE createx(HANDLE x)
{
	x = CreateFile(...);
	return x;
}

int main()
{
	HANDLE f;
	createx(f);
	CloseHandle(f);
}
 
4:08 PM
omfg
4260
Q: The Definitive C++ Book Guide and List

grepsedawkThis question attempts to collect the few pearls among the dozens of bad C++ books that are published every year. Unlike many other programming languages, which are often picked up on the go from tutorials found on the Internet, few are able to quickly pick up C++ without studying a well-written...

 
?
 
that code is not correct jey, you can never assigning anything to f
 
@Froglegs what should i do then? to achieve the goal i though that code would
 
as mill is saying, you should really read a book on this
 
I think you're both wasting your time and our time, because you're asking basic questions on how language works, which would be trivially answered if you had read a book. And C++ is not a language you can just fumble around.
 
4:11 PM
sorry, i didnt knew there was a knoledge restriction in this room
 
And I do mean you're wasting your time because by the time we write out our explanations you'll read 50 pages of the book
 
:|
 
@jeyejow no because you aren't using the x that was passed in
 
@ratchetfreak how can i use it?
isnt the f that x?
cause i pass the f
or no?
 
you shouldn't be passing the f
 
4:12 PM
:V
 
int main()
{
	HANDLE f = createx();
	CloseHandle(f);
}
 
study up on passing by value vs passing by references
 
@user8469759 Okay. Let's go over SFINAE at the most basic level. We define two classes: Yes and No, and do our best to assure that they're different sizes. They we overload Test to return a Yes for one type, and a No for any other type. Test never actually gets called though--instead, we only look at what size of return type it would have if it were invoked with a particular type. We compare the size of that returned value to the sizes of the two types we defined with different sizes.
 
i see, thanks!
@ratchetfreak what if in my createx() i have this:
HANDLE createx()
{
	HANDLE x = CreateFile(...);
	HANDLE y = CreateFile(...);
	return x,y;
}
how do i distinguish between them?
in int main
 
This lets us know what type it would return if we were to invoke it with a particular type. The next part is fairly simple: the one "special" overload type is the base class we want to figure out of something is derived from. That works because a pointer to a derived object can convert implicitly to a pointer to a base object (assuming public inheritance). So, if we have some derived object d, the return type of Test(&d) will be Yes.
 
4:17 PM
between the HANDLE x and Y
 
you aren't returning them both jey
 
no ? :O
 
the return type is HANDLE, as in a single HANDLE
 
@jeyejow No. The return x,y works because that's a comma operator (which you can learn about in any competently written book on C++). The short answer is that in this case it's equivalent to return y; x will simply be lost (leaked).
 
are you saying both the same thing or diferent things? does it work or no?
ok, so how shoud i do this?
HANDLE createx()
{
	//in this function, i need to create 2 handles
	HANDLE x = CreateFile(...);
	HANDLE y = CreateFile(...);
	// after creating them, i return them so i can use them in int main
	return x,y;
}

int main()
{
	createx(); // call the createx function

	// i wanna close X and keep Y alive, how?
	CloseHandle(?x);
}
 
4:21 PM
If you want to return a pair of items, you could define the return type as std::pair<HANDLE, HANDLE> or std::tuple<HANDLE, HANDLE>, or std::vector<HANDLE> or any number of other things, then do something like return {x, y};
 
std::pair<HANDLE, HANDLE> createx()
{
	//in this function, i need to create 2 handles
	HANDLE x = CreateFile(...);
	HANDLE y = CreateFile(...);
	// after creating them, i return them so i can use them in int main
	return {x,y};
}
 
yep
 
ok so i have this in the createx() @JerryCoffin
now how do i close one and keep the other alive in int main?
how can i distinguish them in int main?
 
you access them as .first and .second
 
int main()
{
	std::pair<HANDLE, HANDLE>pair = createx(); // call the createx function
        // pair.first is x
        //pair.second is y

	// i wanna close X and keep Y alive, how?
	CloseHandle(pair.first);
}
 
4:24 PM
std::pair<HANDLE, HANDLE> createx()
{
	//in this function, i need to create 2 handles
	HANDLE x = CreateFile(...);
	HANDLE y = CreateFile(...);
	// after creating them, i return them so i can use them in int main
	return {x,y};
}

int main()
{
	std::pair<HANDLE, HANDLE>pair = createx(); // call the createx function
        // pair.first is x
        //pair.second is y

	// i wanna close X and keep Y alive, how?
	CloseHandle(pair.first);
}
so this will be full code?
or does the createx() doesnt need all that behind?
@ratchetfreak
 
comments are just that, comments
they can be removed
 
do you mean std::pair<HANDLE, HANDLE>pair = createx(); ?
 
you can use auto or you can typedef it
 
ya : auto pair = createx()
same thing
 
so
std::pair<HANDLE, HANDLE> createx()
{
	//in this function, i need to create 2 handles
	HANDLE x = CreateFile(...);
	HANDLE y = CreateFile(...);
	// after creating them, i return them so i can use them in int main
	return {x,y};
}

int main()
{
	auto pair = createx(); // call the createx function
        // pair.first is x
        //pair.second is y

	// i wanna close X and keep Y alive, how?
	CloseHandle(pair.first);
}
this would work?
im confused
:c
 
4:29 PM
ya if you have utility included, and a c++ compiler that isn't pre c++11
 
does the code i posted above this also works?
@Froglegs
 
did you try it?
 
not yet, i build code during the day at test it when i get to my computer at home, here is very dificult because im at work
 
use an online c++ compiler then
 
okk, ill test all when i get home, thanks all for the help and patience ahaha
i gtg cya!
 
 
2 hours later…
6:23 PM
Hi
 
can anyone tell me what is a proxy object??
 
In computer programming, the proxy pattern is a software design pattern. A proxy, in its most general form, is a class functioning as an interface to something else. The proxy could interface to anything: a network connection, a large object in memory, a file, or some other resource that is expensive or impossible to duplicate. In short, a proxy is a wrapper or agent object that is being called by the client to access the real serving object behind the scenes. Use of the proxy can simply be forwarding to the real object, or can provide additional logic. In the proxy, extra functionality can be...
 
std::map and std::set internally implementing a RB balanced tree. What is the complexity if I populate these containers with n elements. Will it be O(n) or O(n* Log n)?
 
2 messages moved from Lounge<C++>
 
thankyou @milleniumbug
 
6:26 PM
Thank you @milleniumbug
 
thank you @milleniumbug
@Steephen the complexity is specified for the member functions en.cppreference.com/w/cpp/container/map/insert
> O(N*log(size() + N)), where N is the number of elements to insert.
 
If I use a constructor and use as follows : std::set<T> firstSet(first.begin(), first.end());
Assume first is std::vector<T> first
 
the time complexity for the constructor is also specified en.cppreference.com/w/cpp/container/map/map
 
6:52 PM
@Steephen If the input items are already sorted, and you specify .end() as the "hint" when you insert the items into the set, you'll get O(N). Otherwise, O(N log n).
 
Thank you Jerry. I really enjoy reading your answers in stackoverflow.
 
anyone know whether using the g++ flags "-static-libgcc -static-libstdc++" to create a DLL is redundant if I were to compile an executable linking against the DLL with the same flags?
 
00:00 - 14:0014:00 - 20:00

« first day (352 days earlier)      last day (2501 days later) »