Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is all in C++, Computer Science Problems: Problem A: \"Undefined symbols fo

ID: 3725050 • Letter: T

Question

This is all in C++, Computer Science Problems:

Problem A:

"Undefined symbols for architecture x86_64:

"Vehicle::getIdgen()", referenced from:

_main in proj5.o"

Code calling it:

cout << "Base idgen: " << Vehicle::getIdgen() << endl;

Code Where it is:

static int getIdgen() {
return 0;
}

B)

"Vehicle.cpp:68:12: error: use of undeclared identifier 's_idgen'

return s_idgen;"

Code Calling it:

static int getIdgen() {
return s_idgen;
}

Code initializing s_idgen:

class Vehicle {
public:
Vehicle();
Vehicle(int n_vin, float *n_lla);
Vehicle(Vehicle &vehicle);
~Vehicle();

friend std::ostream& operator<<(std::ostream& os, const Vehicle& myStr);
Vehicle& operator=(Vehicle& vhs);

void setLLA(float *n_lla);
void move(float *n_lla);

float *getLLA();
int getVIN();
static int getIdgen();
private:
static int s_idgen;
protected:
float m_lla[3];
const int m_vin;
};

Explanation / Answer

The problem is solved where

1) the error i.e., use of undeclared identifier 's_idgen'

is solved by initialization of static data member outside the class

int Vehicle::s_idgen=0;

2) the error i.e.,undefined reference to Vehicle::getIdgen()

is solved by defining static member function outside the class in the following way

int Vehicle::getIdgen()

{

return s_idgen;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote