Question

My main() file does not call to the class created in a .hpp file. It comes out with the error "undefined reference to "___" const.

I want to solve this by only changing the main() .cpp file, not the .hpp file.

.cpp file

include <iostream> include <string> tinclude CourseMember.hpp using namespace std int main0 CourseMember CourseMember(90, Jeff, Goldblum): // initializing the constructor cout<< Member ID is <<CourseMember.getID) << endl; 1/ calling getID) accessor cout <<First Name is << CourseMember.getFirstName << endl; // calling getFirstName) accessor cout<< Last Name is <CourseMember.getLastName () << endl; // calling getLastName() accessor return 0;

.hpp file

#ifndef #define CourseMember-hpp CourseMember-hpp include <string> class CourseMember public: Parameterized constructor param id the students unique identifier aram first the students first rame param last the student s last name CourseMember (int id, std::string first, std::string last) //xxxxxxxxxx Accessor Methods xxxxxxxxxxxxxxxx /kk @return returns id ;リ int getIDi const; x greturn returns first name / std::string getFirstName ) const; /x greturn returns last name/ std::string getLastName () const; private: int id. /.. the CourseMembers ID std:string first name ; /Ak the CourseMembers first name std::string last name: the CourseMembers last name : //end CourseMember #endif /* CourseMember. Ipp */

Thank you!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The main error is that you created the .hpp file. In this file you just initialize the CourseMember class but you not implemented that class in other cpp file so here is the full code with output

main.cpp

#include<iostream>

#include"CourseMember.hpp"

using namespace std;

int main()

{

CourseMember courseMember(90,"Jeff","Goldblum");

cout<<"Member id is: "<<courseMember.getId()<<endl;

cout<<"First name is: "<<courseMember.getFirstName()<<endl;

cout<<"Lasr name is: "<<courseMember.getLastName()<<endl;

return 0;

}

CourseMember.hpp

#ifndef CourseMember_hpp

#define CourseMember_hpp

#include<string>

class CourseMember

{

public:

CourseMember(int id,std::string first,std::string last);

int getId() const;

std::string getFirstName() const;

std::string getLastName() const;

private:

int id;

std::string first_name;

std::string last_name;

};

#endif

CourseMember.cpp

#include"CourseMember.hpp"

CourseMember::CourseMember(int id,std::string first,std::string last)

{

this->first_name=first;

this->last_name=last;

this->id=id;

}

std::string CourseMember::getFirstName() const

{

return this->first_name;

}

std::string CourseMember::getLastName() const

{

return this->last_name;

}

int CourseMember::getId() const

{

return this->id;

}

Output

D. course Member error sohing-Microsoft Visual Studio FILE EDIT VIEW PROJECT BUILD DEBUG TEAM SQL TOOLS TEST ARCHITECTURE ANALYZE WINDOW HELP Quick Launch (Ctrl+Q) 0 , a a .2 Local Windows Debugger, Debug X CourseNumber.cpp Solution Explorer (Global Scope) #includec iostream» #include cour Search Solution Explorer (Ctri+) error solving (1 project) using namespa error solving ember id is: 98 First name is: Jeff Lasr name is: Goldblum Press any key to continue Eint main) r.hpp cout<<Me cout<<Fi cout<<La return e er.cpp View Output Show output from: B 1>--Build st 1> nain.cpp 1> CourseNunber 1> Generating Co 1 Course Member Build: Error List Output Build succeeded O Type here to search ←回匀農 23:03 02-02-2019If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
My main() file does not call to the class created in a .hpp file. It comes...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is a simple C++ class using inheritance, I have trouble getting the program to work....

    This is a simple C++ class using inheritance, I have trouble getting the program to work. I would also like to add ENUM function to the class TeachingAssistant(Derived class) which is a subclass of Student(Derived Class) which is also a subclass of CourseMember(Base Class). The TeachingAssistant class uses an enum (a user-defined data type) to keep track of the specific role the TA has: enum ta_role {LAB_ASSISTANT, LECTURE_ASSISTANT, BOTH}; You may assume for initialization purposes that the default role is...

  • "Function does not take 0 arguments". I keep getting this error for my last line of...

    "Function does not take 0 arguments". I keep getting this error for my last line of code: cout << "First Name: " << employee1.getfirstName() << endl; I do not understand why. I am trying to put the name "Mike" into the firstName string. Why is my constructor not working? In main it should be set to string firstName, string lastName, int salary. Yet nothing is being put into the string. #include<iostream> #include<string> using namespace std; class Employee {    int...

  • Requirements I have already build a hpp file for the class architecture, and your job is to imple...

    Requirements I have already build a hpp file for the class architecture, and your job is to implement the specific functions. In order to prevent name conflicts, I have already declared a namespace for payment system. There will be some more details: // username should be a combination of letters and numbers and the length should be in [6,20] // correct: ["Alice1995", "Heart2you", "love2you", "5201314"] // incorrect: ["222@_@222", "12306", "abc12?"] std::string username; // password should be a combination of letters...

  • Write a C++ Program. You have a following class as a header file (dayType.h) and main()....

    Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public:     static string weekDays[7];     void print() const;     string nextDay() const;     string prevDay() const;     void addDay(int nDays);     void setDay(string d);     string getDay() const;     dayType();     dayType(string d); private:     string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...

  • The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried t...

    The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...

  • Requirements: Finish all the functions which have been declared inside the hpp file. Details: st...

    Requirements: Finish all the functions which have been declared inside the hpp file. Details: string toString(void) const Return a visible list using '->' to show the linked relation which is a string like: 1->2->3->4->5->NULL void insert(int position, const int& data) Add an element at the given position: example0: 1->3->4->5->NULL instert(1, 2); 1->2->3->4->5->NULL example1: NULL insert(0, 1) 1->NULL void list::erase(int position) Erase the element at the given position 1->2->3->4->5->NULL erase(0) 2->3->4->5->NULL //main.cpp #include <iostream> #include <string> #include "SimpleList.hpp" using std::cin; using...

  • Greetings, everybody I already started working in this program. I just need someone to help me...

    Greetings, everybody I already started working in this program. I just need someone to help me complete this part of the assignment (my program has 4 parts of code: main.cpp; Student.cpp; Student.h; StudentGrades.cpp; StudentGrades.h) Just Modify only the StudentGrades.h and StudentGrades.cpp files to correct all defect you will need to provide implementation for the copy constructor, assignment operator, and destructor for the StudentGrades class. Here are my files: (1) Main.cpp #include <iostream> #include <string> #include "StudentGrades.h" using namespace std; int...

  • I need to get this two last parts of my project done by tonight. If you...

    I need to get this two last parts of my project done by tonight. If you see something wrong with the current code feel free to fix it. Thank you! Project 3 Description In this project, use project 1 and 2 as a starting point and complete the following tasks. Create a C++ project for a daycare. In this project, create a class called child which is defined as follows: private members: string First name string Last name integer Child...

  • Design a class named Triangle that extends GeometricObject class. The class contains: Three double data fields...

    Design a class named Triangle that extends GeometricObject class. The class contains: Three double data fields named side1, side2, and side3 with default values 1.0 to denote three sides of the triangle. A no-arg constructor that creates a default triangle with color = "blue", filled = true. A constructor that creates a triangle with the specified side1, side2, side3 and color = "blue", filled = true. The accessor functions for all three data fields, named getSide1(), getSide2(), getSide3(). A function...

  • Write a MyString class that stores a (null-terminated) char* and a length and implements all of...

    Write a MyString class that stores a (null-terminated) char* and a length and implements all of the member functions below. Default constructor: empty string const char* constructor: initializes data members appropriately Copy constructor: prints "Copy constructor" and endl in addition to making a copy Move constructor: prints "Move constructor" and endl in addition to moving data Copy assignment operator: prints "Copy assignment" and endl in addition to making a copy Move assignment operator: prints "Move assignment" and endl in addition...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT