« first day (1410 days earlier)      last day (1659 days later) » 

07:01
@nwp thanks
 
2 hours later…
08:49
Umm.. guys, In the diamond problem in C++, if the top level class is abstract, which has been inherited into one abstract class and one non-abstract class, and if there is another class which inherits these two, in that case does the pure definition override the normal definition?
 
2 hours later…
10:42
anybody have any idea on calling masstransit from c++
 
2 hours later…
12:59
Sooo... we use vectors to store ints... std::vector<int> test = {1,2,56,100}; as soon as we call test.size() to determine the amount of items in there, it returns random numbers like 93994949 or 123123058389... thats clearly not the amount of items in there... we googled for hours and couldnt find a damn trick to solve this issue, we also commented all importants parts of our programm out and it still returns wrong numbers... any idea ?
@genaray show us the code then
or set a data-breakpoint in the size/end
to see where it gets overwritten
Thats the problem... theres no code to show... we literally have one main class with one line and a import of a class storing a vector of those items... as soon as we debug trough the program it returns random sizes each time
so linking stuff from different compilers? different standard library implementations?
nwp
nwp
Sounds like you are accessing uninitialized memory.
sounds like there's still some code, the devil is in the detail
how you're accessing the vector, how you're creating the instance, etc.
13:06
Theres literally no other code... but we just made a discovery... it looks like the debugger returns wrong values on .size() when we print .size() it returns the right value... thats really strange
sounds normal to me if it's msvc in release mode
@genaray I'm betting on Undefined behavior overwriting the data member that stores the size
When debugging in release mode in VS you can't ever rely on the values. I've hat to look at the disassembly a bunch of times and manually cast some pointer values to get the actual values to show
 
1 hour later…
14:35
umm.. guys, what are the advantages of using getline over std::cin when accepting an object of std::string?
nwp
nwp
You mean std::getline(std::cin, str); vs str << std::cin;?
vs std::cin >> str (I didn't know know you could do str << std::cin actually )
nwp
nwp
You can't, I'm just dumb.
The difference is that std::getline reads a line and std::cin::operator>> reads a word.
15:00
@nwp You think that... but you do not know me... XD
15:16
Why dis code no work, lol?
unsigned char *address = NULL; std::cout << address + 0x1 << std::endl;
But dis one fine
int *address = NULL; std::cout << address + 0x1 << std::endl;
GCC version 6.3.0
15:52
5 messages moved from Lounge<C++>
@Lapys define work?
hi, I have a report.h file in which I have defined a class Report inside the namespace cong. I have also overloaded operator<< which is also in the same file and in the same namespace but it looks like the operator<< is not accessible after including the report.h file in another f.cpp file. How do I go about it?
I overloaded operator<< as a nonmember function
@octopus you are allowed to specialize operator<< in namespace std; for this en.cppreference.com/w/cpp/io/basic_ostream/operator_ltlt2
but make sure you match the declaration and are using the template and not the class
@Mgetz Okay I will check it out now, thanks
16:26
Please take a look at the challenge am facing as demonstrated here:
any directions please?
I think I have found a way to handle it
can you verify if it is the best way to?
16:57
Is there some compiler attribute/way to silence unitialized use warning for a function call? __attribute__((unused)) doesn't seem to work.
I.e. the compiler (at least clang) complains about the variable being used without being unitialized even then it's passed to a function that has it's argument marked as unused
17:12
Hey all, I'm trying to write a function that computes pi to the nth digit. I have it almost working but it fails for some cases.

#include <cmath>
#include <algorithm>
double myPi(int n) {
std::string ten = "1";
for(int i = 0; i < n; i++){
ten += "0";
}
std::string tmp_ten = (ten + "0");
float prior = ((float)(int)(M_PI*std::stoi(tmp_ten))/std::stoi(tmp_ten));
std::string prior_str = std::to_string(prior);
prior_str.erase(remove(prior_str.begin(), prior_str.end(), '0'), prior_str.end());
if((int(prior_str.back())-48) >= 5){
I'm not really sure what I could be doing wrong.
17:33
What do you mean by "fails for some cases"? Anyway, this code is kinda ugly and works only for small n for obvious reasons.
17:44
Okay
I'm working through edabit challenges
and it fails for pi(8)
myPi(9) and myPi(7)
I think I'm just going to do cases and directly return the number
18:00
@earlyriser01 there is a high chance, with the way you are doing things, that you are just running out of float precision.
Ah Isee
@Mgetz Does not crash the compiled executable (a segfault I'm guessing?)
If n is bounded by some small number, then you can use something like #M_PI (or just copy-paste digits yourself into a string and just return "3.14..."[i];, if n is bigger, then you can just google the formula for nth digit of pi and use that. But w.r.t your original question about what you are doing wrong: you are using float numbers and multiplying them by a very big number.
@Lapys my guess is they are expecting to see addresses and are getting a string or garbage because they forgot that char* has an output overload
@Mgetz Honestly laughing at how "they" could forget something so simple. My initial guess to the problem was that it was a special address (like the SP) and the compiler really didn't like that XD
18:08
@Lapys possible, but we've seen that question more than once
I see.
Thank you
How do I round this?
3.1415926535897
I want to remove the 7 and round it
@Mgetz Would those special addresses even be managed within the program's virtual memory?
@Mgetz Lol, wonder what it's like answering the same ol' question people ask
@Lapys no idea
@Lapys usually we encourage people to search the site first
18:26
Ended up just hardcoding each case.
Don't really like that approach for obvious reasons but it passed the edabit challenge tests
@earlyriser01 Would you like some sample code sometime soon?
No it's okay. What I hard-coded ended up passing the edabit tests. Of course, I spent a lot of time trying to not do that and to actually compute the value of pi to the nth decimal place.
Complete with rounding
Hence why my first code attempt that I posted above is so hacky to do the rounding
If anyone has a better approach, I would be more than happy to see it as hard-coding is something I try to stay away from
18:45
@Mgetz Thanks, by the by

« first day (1410 days earlier)      last day (1659 days later) »