Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help just writing a fragment of code in C++, I just need help writing the copy constructor. I have highlighted the area that is

Need help just writing a fragment of code in C++, I just need help writing the copy constructor. I have highlighted the area that is the copy constructor which needs fixing

Question:

Write a public copy constructor as follows:

  • construct the type_ member with sho.type_ (where sho is the argument passed to the copy constructor) in the constructor's member initializer list, and,
  • within the body of the constructor write an if statement to appropriately copy the function pointer value, i.e., sho.sa_handler_ or sho.sa_sigaction, as follows:
    • if type_ == op_type::sigaction then copy sa_sigaction_ otherwise copy sa_handler_.

NOTE: You would not set sa_sigaction_ and sa_handler_ in the member initializer list since (i) it would overwrite the other union member, and, (ii) only one of the two is being used but one doesn't known which one will be used until run-time.

//////////////////////////////////////////Code Below//////////////////////////////////

class signal_handler_op { private:

enum class op_type { error, default_, ignore, traditional, sigaction };

public:

using traditional_op_type = void(*)(int);

using sigaction_op_type = void(*)(int, siginfo_t *, void *);

private:

traditional_op_type static const ERROR;

traditional_op_type static const IGNORE;

traditional_op_type static const DEFAULT;

op_type type_;

union { traditional_op_type sa_handler_; sigaction_op_type sa_sigaction_; };

public:

signal_handler_op(): sa_handler_ {DEFAULT} {

type_ op_type::default_

}

//BELOW IS THE COPY CONSTRUCTOR THAT IS DONE INCORRECTLY AND NEEDS TO BE FIXED

signal_handler_op(signal_handler_op const & sho): type_ {sho} {

}

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

Recommended Textbook for

Neo4j Data Modeling

Authors: Steve Hoberman ,David Fauth

1st Edition

1634621913, 978-1634621915

More Books

Students also viewed these Databases questions