0

I am Starting learning C++ from scratch, and now I am trying to import this custom header to one of my cpp. Its a pretty basic class.

ClientData.h

#ifndef CLIENTDATA_H
#define CLIENTDATA_H

#include <string>
using namespace std;

class ClientData{
public:
    ClientData(int=0, const string & = "", const string & = "", double = 0);

    void setAccountNumber(int);
    int getAccountNumber() const;

    void setLastName(const string &);
    string getLastName() const;

    void setFirstName(const string &);
    string getFirstName() const;

    void setBalance(double);
    double getBalance() const;

private:
    int accountNumber;
    char lastName[15];
    char firstName[10];
    double balance;
};

#endif

tutor.cpp

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cstdlib>
#include "ClientData.h"

using namespace std;

int main(){
  ClientData blankClient;
  return 0;
}

I get an error of: undefined reference to ClientData::ClientData(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, double)

For an extra info: I am using MinGW Compiler, and I also name the header ClientData.h placed under the include folder of MinGW Compiler directory. I run this code under sublime text.

What should I do to solve this? Thankyou

Jovan
  • 763
  • 7
  • 26
  • What command did you use to build/compile your project? Also, show us your source file(.cpp) – Jason Dec 09 '22 at 07:59
  • The error message means that you have not defined your `ClientData` constructor. None of the code you have posted contains a `ClientData` constructor definition. So either you don't have such a definition or you have not posted all the code you have. Do you think you have defined the `ClientData` constructor? – john Dec 09 '22 at 08:03
  • I see so this section of code `ClientData(int=0, const string & = "", const string & = "", double = 0);` is not enough to be called constructor.. @john thanks, yes I still make an "outline" of it first in this practice, to see if its valid or no. – Jovan Dec 09 '22 at 08:25
  • 1
    @Jovan The code you are referring to is a *declaration* not a *definition*. Understanding the difference is crucial here. – john Dec 09 '22 at 08:37
  • @John Noted, I have filled the definition of the class, and now the header include is working – Jovan Dec 09 '22 at 09:10

0 Answers0