I'm new to using user created libraries on dev-cpp, and I've been getting some errors, so I would like to make sure I'm doing things right. first...
.h file-
#ifndef mylibrary_h
function declarations
#define mylibrary_h
#endif
right?
now standard protocol is for the mylibrary.cpp file to include the mylibrary.h file, and for the driver to include the mylibrary.cpp file. I try this, but I get linking errors. Also, I put my files in the "include" folder. Is this correct?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm new to using user created libraries on dev-cpp, and I've been getting some errors, so I would like to make sure I'm doing things right. first...
.h file-
#ifndef mylibrary_h
function declarations
#define mylibrary_h
#endif
right?
now standard protocol is for the mylibrary.cpp file to include the mylibrary.h file, and for the driver to include the mylibrary.cpp file. I try this, but I get linking errors. Also, I put my files in the "include" folder. Is this correct?
Once I include my .h file, it says I have an unterminating #if statement and garbage at the end of my #ifndef statement.
This is not mine. Just wanted to give something to go by.
Hope it helps.
#ifndef BOX_H
#define BOX_H
class Box
{
public:
// Constructor
Box(double lengthValue = 1.0, double breadthValue = 1.0, double heightValue = 1.0);
// Function to calculate the volume of a box
double volume();
private:
double length;
double breadth;
double height;
};
#endif
Larry
Note:
// Constructor
Box(double lengthValue = 1.0, double breadthValue = 1.0, double heightValue = 1.0);
and -
// Function to calculate the volume of a box
double volume();
These two are defined in another file. 'Box.cpp'.
Larry
Here is the other file that has the definitions.
#include <iostream>
#include "Box.h"
using namespace std;
// Constructor definition using an initializer list
Box::Box(double lvalue, double bvalue, double hvalue) : length(lvalue),
breadth(bvalue),
height(hvalue)
{
cout << "Box constructor called" << endl;
// Ensure positive dimensions
if(length <= 0.0)
length = 1.0;
if(breadth <= 0.0)
breadth = 1.0;
if(height <= 0.0)
height = 1.0;
}
// Function to calculate the volume of a box
double Box::volume()
{
return length * breadth * height;
}
Larry