Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Debugging Practice

The code below contains five (4) 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[6]{ 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. }

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Programming questions