I am trying to get a header file and source file to intergrate into a main c++ file.The class is in the header file, the functions are in the source file. I cannot get the source file to compile due to errors with my function prototypes. I am sure this is an easy fix I am just not able to quite understand the process for using the class by the functions. I dont know how to properly copy code to a forum. If someone can tell me how I will repost this neatly. I need alot of help thank you in advance.
header file.
#ifndef cResistor_H
#define cResistor_H
class cResistor //generates class for Resistor data
{
public:
cResistor();
cResistor( double m_dResValue, double m_dTolerance); //
void DisplayResistor();
~cResistor( );
#include "Resistor.h" //Header file to use to access information.
#include <iostream> //Used for O/P for the functions
#include <iomanip> //Used for spacing
using namespace std;
void cResistor::DisplayResistor(void); //Function prototype for displaying resistor.
cResistor::cResistor(double m_dResValue, double m_dTolerance); //Function prototype for resistor calculations.
On your source file you should not put ANY prototypes. Remove the prototypes from the source file.
Thirdly, you cannot do that in your main method cResistor::cResistor();. You have to declare a pointer to the object.
Try cResistor* resistor = new cResistor();
But your source file does not have any implementation for this constructor either. So it will give error unless you implement this in your source file
1 2 3
cResistor::cResistor()
{
}
Fourthly, (but i should put this suggestion first), you should seriously READ about Object Oriented programming or Classes on C++.
Read this http://www.cplusplus.com/doc/tutorial/classes/
Thanks greenscar for your tips and direction. I reviewed the class tutorial and with a little prodding from another student in my class I finally cleared up my errors and got the expected output. I finally had the AHa moment last night during the lecture review and I think I got the basics down with the implementation. Now I just need a little more practice. Thanks again for your time.