« first day (1360 days earlier)      last day (1498 days later) » 

12:05 AM
@CătălinaSîrbu What kind of error would you expect?
 
i gave you another example
void operator()(string s)
and X(string s)
how does the compiler know what function to call when doing X obj("a")
in the meantime I asked about it and i got an answer that you need an instance in order to be able to call an operator function. So i believe in that declaration is too early to talk about an instance.
 
Hmm, I'm confused now.
In your first example, X(string s) is the constructor.
 
Ok, so, yes, X x("a") is declaring and initializing an instance of X.
You could probably do something crazy like X x("a"); (X("b"))(x);
You don't even need the extra set of parenthesis: x("a"); X("b")(x);
Go super-crazy: X("u")(X("v"));
 
 
9 hours later…
9:00 AM
If AddressSanitizer doesn't say anything, does that mean everything is ok with the program?
 
 
2 hours later…
11:28 AM
Hello,
I need an advice. I get a composite value from a sensor, e.g. 123456789012. From this value I get my correct measured value, for example, the first measured value x1 are the first two digits (12), the second measured value x2 are the next two values ​​(34) etc., so that I have a total of 6 measured values ​​(x1, x2, y1, y2, z1, z2). My question now is, in which data container (vector, list, array) can I best store this data in a meaningful way? I need it in a function in which I then plot it.
 
if the size of the data is always the same, an array is generally the most optimal
 
Hmm, so then in the plot function if I want to plot x1, y1, and z1 over the time I actually wanted to write something like plot(time, myContainer.x1) , plot (time, myContainer.y1) plot(time, myContainer.z1) But when I use an array I have to right something like plot(time, array[0]) so this is not intuitive
 
Ah, then use a struct?
struct Data {int x1, x2, x3, y1, y2, y3; };
 
and how can I assign values to the data, e.g. x1 is 20
Can I do something like struct Data {int x1=12; }; then plot(time, Data.x1) ? ;D
 
A struct is like a class, except that everything is public by default, so you'll have to construct an object, assign to it, then pass it around.
struct Data
{
  int x1 {};
  int x2 {};
  int x3 {};
  int y1 {};
  int y2 {};
  int y3 {};
}

Data myDat = {[value for x1], [value for x2], [value for x3], [...] };
then you'll be able to access your data using plot(time, myDat.x1);
 
11:43 AM
Oh, okay thank you. but what about a map, would this not be suitable too? Because I have then Key-value paitrs
 
Maps are nice when you're not sure exactly what will be all the keys you'll need. Since your data here seem pretty well defined I don't see how a map would be more useful.
They're also less efficient, generally.
If you don't always have all of the measures, then perhaps this could be interesting, but that doesn't seem like your situation.
 
Okay thank you, from the sensor I get real time data every second. I will try the struct. I thought because of instantiating and so on this would be a little bit too much for this 'easy' issue ;D
 
Well the "most efficient" would probably be a classic c++ array.
You can use an enum to create the keys to figure out a bit more what's going on.
enum Keys
{
  KeyX1,
  KeyX2,
  KeyX3,
  KeyY1,
  KeyY2,
  KeyY3,
  KeysCount
};

int data[KeysCount] = {[value for x1], [value for x2], [value for x3], [...] };

plot(time, data[KeyX1]);
(untested code, there might be compilation error here and there, but you get the spirit).
 
Uh, that seems good thank you. Should I create the enum/struct in my function or outside the function then use it in my function?
with function I mean the fuinction which trnasforms my sensor value to my coordinates
 
Depends entirely on where you need it. If you need it only in the function and it's only for you to make it look clearer, you might want to keep it in the function, otherwise you can move the enum/struct in the header file so that other "entities" can use it too.
 
11:58 AM
Okay, thanks :)
 
Good luck :)
 
 
2 hours later…
2:05 PM
Hey, when I have this value from a sensor: 00000015255668898 what type is this?
It comes as a string but when I convert it to int there is a wrong value
 
if you have an integer conversion function that tries to auto-detect the number-base then a number starting with "0" will be interpreted as an octal number
didn't you say this was fixed-width digits anyway? in that case you shouldn't try to convert the whole string before splitting it up
 
Oh, okay. Because the sensro Data comes actualle as an QByteArray ( in Qt), then I convert it to String because I have to do something with it (QString)value - now I actually wants it to be as a byte again
@PeterT I just said that for simplify it. Acutally my Sensor mesasures the acceleration and the orientation - this is send as a QByteArray like this 000002565691556 e.g. The zeroos mean that the acceleration is 0 but later this will be something like 15236554658794
in this QByteArray the value consists of x,y,z for acceleration and x,y,z for orientation and in my function I want to get this coordinates by transforming the QByteARRAY
Ah, to convert the string to QByteArray again it is done with toUft8() function in Qt :D
 
It also just has a constructor for it
or was your issue that it was then looking at the UTF-16 data
 
I think so
 
ok, but why do you even need it to be QByteArray again, sounds like a bunch of needless conversions
 
2:21 PM
Yes you are right. It is a little bit more complicated in the moment, actually I should get from by UFT( QbyteArray Value a float value like acceleration_x = 0.5 m/s² and so on - and this value I need to pass to the plot()-function
but at the momentr i don't know how to get the correct coordinates from my QbyteArray-value (should be in the data sheet of the sensor)
 
3:09 PM
@PeterT I ended up downloading a program called SASM on windows which both compiles and debugs NASM code. Thanks for trying to help out. I will try to accomplish this on linux (one day, hopefully).
 
3:25 PM
I still don't understand why having the constructor Class (int param) : param{param} is called when executing the following Class obj = 1... It is an implicit call of the constructor because it has a parameter of type int .. or what?
 
yes
 
you said something like if T a = b , the constructor is called only if b ... and looks like this piece of information avoided me:))
 
So if I understand well, T a = b if b is not derived from T, and if inside T class there is a constructor that takes as paramter a b type, then that constructor will implicily be called in order to instantiate the object? Am I close?
as It is said that a converting constructor specifies an implicit conversion from the types of its arguments (if any) to the type of its class.
 
Yes, that's what will happen.
 
3:39 PM
thank you
It is funny how you can have the feeling that you understand a thing, and a few days later you know that thing but you can't actually explain for yourself what that thing does:))
 
nwp
@CătălinaSîrbu Whenever an object is created a constructor is called, independent of how it is created. If the constructor is not called then the object does not exist. Sometimes it's an implicitly declared constructor or some wording for builtins that technically don't have constructors (I think) but get created anyways.
@CătălinaSîrbu Welcome to C++. Even if you learn it for 10 years that keeps happening.
 
:)) glad I'm here tho
I wish I could also understand the rest of discussion on this chat :). In my programming evolution (if I can call it so) I observe that 4-5 years ago when I was writing the code on paper in pseudocode and things were unclear, I would just search online for the answer. The way I was searching for answers was interesting as I only looked for things that I can understand with the minimum effort ( without learning concept B for explaining concept A ).
As the years passed by, I saw that I started to scroll down for more explanations at every thing I search for. Even thoguh, I still need some more years to catch up with you
 
 
1 hour later…
4:46 PM
Hello guys, can anyone help me with a task?
 
just say what exactly you need help with and then people can see if they can help you
 
The drawback of the desktop application is it's difficult to install and upgrade an application. You need an IT team to do that in a business environment. Is there any way that this can be handled better?
so that the application update happens seamlessly
 
@Sameer sadly there's no general tool that works for all situations. But things get a lot easier in any case if you can package the application in something like an *.msi file
for pubic consumer-facing applications most operating systems have an app store now, but that doesn't help with all use-cases
 
 
2 hours later…
6:58 PM
So I'm using try-catch statement where I throw runtime_error if something bad happens and then I catch it with catch function
The problem I'm having, once I catch the error, the program keeps catching it infinitely
I thought once I catch the runtime error , program should stop
 
No, catching it means "I'll handle it"
if you want to crash you can rethrow it or call std::terminate
 
how do I rethrow it ?
some example maybe ?
 
throw;
 
I don't follow. So my code structure looks like this:
try{
if throw runtime_error("ahshsa")
else if [OK]
else if [OK]
else throw runtime_error(sdsa)
} catch (exception ex) {cout << ex.what() << endl; }
And I keep getting infitely many cout <<ex.what()
 
right, inside the catch block you can call "throw;" and have it rethrow the exception
or, you could just not catch it all if you don't want to handle it
 
7:05 PM
aham I think I got it now
thenks
Is using throw inside a catch block good practice ? I mean, It works fine, but I'm not sure if that's the point of using try-catch statement .
 
You're right, in most cases it defeats the purpose of even using try{}catch(){}
But there is some siturations where you want to do some local cleanup or logging and then delegate the exception to other handlers
because if you are just using "throw;" as the only meaningful code in you catch block then you can just delete the whole try catch and get the same behavior
 
So try-catch should be used if the programmer wants to handle it ?
 
Yes
why use it otherwise?
 
Well I'm supposed to use std::runtime_error in my hw and I could only connect it with crashing program
runtime_error reminds me of crashing
Idk why
Is using throw without catch a known thing to do ?
 
7:24 PM
Yes, that's common. Because you can also catch it somewhere waaaay up the callstack
that's one if the reasons to use exceptions in the first place, so that you don't have to manually propagate errors
while also cleaning up any local resources along the way to the handler
 
What do you mean by catching it way up the callstack ?
 
void f(){throw 2;}
void g(){f();}
void h(){g();}

void main(){
try{h();}catch(...){std::cout << "ex occured";}
}
 
aham
What about throwing without any catch at all?
That wouldn't be so common ?
 
Not sure, how common it is. But I wouldn't see it as unusual for smaller, shorter-running tasks
 
Okay that makes sense
 
7:34 PM
but usually, for end-user facing programs you want to catch it main at the latest to print some more or less meaningful error message
 
Yeah , only throwing ends up with pretty messy error messages
 
I guess it's noteworthy that not catching exceptions is common during development/debugging. Because most debuggers will break on unhandled exceptions
 
It's actually pretty common to have code that is written so it could throw, and not have anything to catch it. Just for example, almost all the standard containers can throw (e.g., if you run out of memory), but lots or people write programs that never attempt to catch those exceptions.
 
Thanks guys
 
 
2 hours later…
9:41 PM
Is it possible to use make_unique after a unique pointer has been created? I have a situation where I have some (very large) array of unique pointers to data, and I do not want to actually create and object until I need it - which means they are not initialized to anything
I was previously getting a reference to the unique pointer and setting the pointer equal to make_unique<myObject>() which seemed to work fine before, but now I think it's causing heap corruption
I tried using .reset, but .reset() does not take a unique pointer
 
a.reset(b.release());
or just a=std::move(b)
 
So a.reset((std::make_unique<myObject>()).release) or a = std::move(make_unique<myObject>())? Or are you suggesting not doing that?
 
oh, I though you already had a unique_ptr
 
No. I have what amounts to a bit array of unique pointers, which are not initialized. I am creating objects on the fly when I need them.
 
the a= std::make_unique() should be fine by itelf
the std::move is redundant there
 
9:47 PM
Huh. It never did before (for several weeks) but now when I get to that make_unique it causes a segmentation fault
And apparently heap corruption
 
seems like a valgrind or asan run might be in order
 
it's just a C++11 backport of the C++14 feature though, taken from Stroustrup, hopefully that's not the fault
Yeah, might have to. It's a little awkward with this program but only option
 
Why does stringstream object become useless after >> operation ?
e.g.
stringstream s;
int x=3,y;
s << x;
s>> y;
s << 23; [Doesnt work]
 
10:08 PM
You've hit end of "file", so you need to reset the stream before anything will work again.
 
.clear() ?
thanks
 
10:37 PM
np
 

« first day (1360 days earlier)      last day (1498 days later) »