function in cpp file for .h doesn't get recognized in cpp file for the main()

Below is an excerpt from the Car.cpp for Car.h

#include "Car.h" // Class Definition file
#include <stdio.h>
#include "stdafx.h"
#include <string.h>


// Class Default Constructor

Car::Car(int YearofModel, string Makeby, int Spd)
{
YearModel = YearofModel;
Make = Makeby;
Speed = Spd;
}


void displayMenu()
{
cout <<"\n Menu\n";
cout << "----------------------------\n";
cout << "A)Accelerate the Car\n";
cout << "B)Push the Brake on the Car\n";
cout << "C)Exit the program\n\n";
cout << "Enter your choice: ";
}
===========================================
Below is an excerpt from automobile.cpp that has main()
#include "stdafx.h" // Defines IDE required external definition files
#include <iostream> // Defines objects and classes used for stream I/O
// Class Definition header file(s)
#include "Car.h"
#include <string.h>

// Namespaces utilized in this program
using namespace std; // Announces to the compiler that members of the namespace "std"
// are utilized in this program

int main()
{


char choice; //Menu selection



cout << "The speed of the SUV is set to: " << Speed <<endl;
Car first( 2007, "GMC", Speed);

//Display the menu and get a valid selection
do
{
displayMenu();


===========================

So call to displayMenu above receives an error message that it's undefined.
Do I have to do something in the header file?

It is likely you have a linking problem.

Not sure how your compiler works but the one I use I need to put all my header files in the compilers library/include folder so it knows where to find it.

If its not that then sorry I couldn't be of more help.
displayMenu is in your car.cpp file.

When your automobile.cpp file is being compiled, the compiler doesn't see the declaration for displayMenu. Not clear if there is one, since you didn't post car.h.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
so below is the Car.h file, displayMenu is declared there so I don't know why it's not recognized.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  #pragma once
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

  
class Car
{
	// Public Interface

private:
	 

	//  Variable Declarations
	int YearModel, Speed=0;
	std::string Make;


public:
	// Class Constructor(s)
	Car(int, string, int);

	//Client Methods
	string getMake();
    int getModel();
    int getSpeed();
    void Accelerate();
 	void Brake();
 	void displayMenu();

	// Class Destructor
	~Car(void);


};


I found the answer. I need to clone a class. like Car CCar; CCar.displayMenu;

Thanks though.
Topic archived. No new replies allowed.