I'm studying an old test and I was wondering if my answers to these are correct. I posted a screenshot if it below
i. Not sure about this one. I'd guess 1.
ii. 2
iii. this->x, 3.
iv. catch
b) i. Is it because you can't set f to a value directly like that? Pretty sure you can't, or is it something to do with the const/missing bracket behind bar?
Not really 100% sure on any of them and #1 I'm really unsure about. If anyone could help me it would be great!
Thanks I'll read those. For 4), can't you set a Foo value equal to an int though, since one of the members is an int? Or do you need to do it like Foo x; f.function=22;?
Also it asked what's wrong with this down the page, but I'm not sure if it's wrong because average has no type, or if because values is unintalized, or something else entirely.
So for one, is c correct since it's taking a const reference? And for the part b 1), the ; is missing but my compiler won't run the code either way. Is the structure of saying const Foo f=1; not valid?
The statement 'const Foo f = 1' is invalid because there is no conversion given from 'int' to 'Foo'. They're two different types and the compiler doesn't know how to convert from an 'int' to a 'Foo'. You could put in a constructor that took an 'int' or an '=' operator overload to do the conversion.