0
//Header FILE:
#ifndef BMI_H_INCLUDED
#define BMI_H_INCLUDED

#include<iostream>
#include<string>
using namespace std;
class BMI{
public:
//default constructer
BMI();
//overloaded
BMI(string,int,double);
private:
string newName;
int newHeight;
double newWeight;
};


#endif // BMI_H_INCLUDED
//Implementation file:
#include "BMI.h"
BMI ::BMI(){
newHeight=0;
newWeight=0.0;

}
BMI::BMI(string name,intheight,double weight){
newName=name;
newHeight=height;
newWeight=weight;
}
//Main file:
#include <iostream>
#include<string>
#include "BMI.h"
using namespace std;

int main()
{
string name;
int height;
double weight;
cout<<"Name:\n";
getline(cin,name);
cout<<"Height(Inches):\n";
cin>>height;
cout<<"Weight(Pounds):";
cin>>weight;
BMI person_1("John",89,90.0);
//I get the error on the above line error is             //undefinedreferenceto`BMI::BMI(std::string, int, double)'



}

Does anyone have any idea why this keeps happening to me?

I use Codeblocks and if so how can I fix this and prevent it from happening again.

This happens every time I separate classes into headers and cpp files. This is just one of the many times my program fails to compile due to this.

Simon
  • 1,616
  • 2
  • 17
  • 39
Twoshock
  • 7
  • 3

1 Answers1

3

in BMI::BMI(string name,intheight,double weight){ theres no space between int and height.

This causes BMI person_1("John",89,90.0); to refer to a constructor that doesn't exist.

Olivier Poulin
  • 1,778
  • 8
  • 15