Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The code below contains five (5) syntactic errors under C++17 standard (errors that are caught by a compiler or generate crashes/undefined behaviour at runtime). 01.

The code below contains five (5) syntactic errors under C++17 standard (errors that are caught by a compiler or generate crashes/undefined behaviour at runtime).

01. // A.h 02. #ifndef A_H 03. #define A_H 04. 05. struct A 06. { 07. public: 08. double m_val; 09. public: 10. A operator+=(const A& other) 11. { 12. this->m_val += other.m_val; 13. return *this; 14. } 15. double getValue() const { return m_val; } 16. }; 17. 18. decltype(A().getValue()) operator+=(double& val, const A& other); 19. 20. // "data" is an array of "N" elements of type "T" 21. template 22. T process(const T* data) 23. { 24. T sum{}; 25. for (const auto& elem : data) 26. sum += elem; 27. return sum; 28. } 29. #endif 01. // A.cpp 02. #include "A.h" 03. 04. decltype(A().getValue()) operator+=(double& val, const A& other) 05. { 06. return val += other.getValue(); 07. } 01. // main.cpp 02. #include 03. #include "A.h" 04. using namespace std; 05. 06. int main() 07. { 08. int arrI[5]{ 0, 1, 2, 3, 4, 5 }; 09. cout << process(arrI) << endl; 10. 11. A arrA[5]{ {1.2}, {2.3}, {3.4}, {4.5} }; 12. cout << process(arrA) << endl; 13. } Your task is to identify each one by the file name and line number and explain why the error appears, what C++ standard rule is broken, what C++ feature is misused and how the error should be fixed. Your answer will be evaluated based on clarity of the text and the show of understanding of the concepts that are involved in the error.

Write in the answer box your solution, using the following template:

Error 1:

Error 2:

Error 3:

Error 4:

Error 5:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions