C++ Programing help: Q20: Define the function pointers that can be used to assig
ID: 3859755 • Letter: C
Question
C++ Programing help: Q20: Define the function pointers that can be used to assign the two overloading static methods of the Automobile class below to the function pointer variables.
#include <iostream>
#include <string>
using namespace std;
class Automobile
{
private:
string Make;
int Year;
string Model;
public:
Automobile()
{
Make = "";
Model = "";
Year = 0;
cout << "Automobile default constructor is called." << endl;
}
Automobile(string make, string model, int year) :
Make(make),
Model(model),
Year(year)
{
cout << "Automobile constructor is called." << endl;
}
Automobile(const Automobile & src)
{
Make = src.Make;
Model = src.Model;
Year = src.Year;
cout << "Automobile copy-constructor is called." << endl;
}
public:
~Automobile()
{
cout << "Automobile destructor is called." << endl;
}
public:
const Automobile & operator=(const Automobile & src)
{
Make = src.Make;
Model = src.Model;
Year = src.Year;
cout << "Automobile assignment operator (=) is called." << endl;
return *this;
}
public:
static Automobile * CreateAutomobiles(int count)
{
return new Automobile[count];
}
static Automobile * CreateAutomobiles()
{
Automobile autoMobiles[3];
return autoMobiles;
}
};
Explanation / Answer
functional pointer for
static Automobile * CreateAutomobiles(int count)
{
return new Automobile[count];
}
is
(Automobile *)(*fun)(int);
functional pointer for
static Automobile * CreateAutomobiles()
{
Automobile autoMobiles[3];
return autoMobiles;
}
is
(Automobile *)(*fun)(void);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.