C
Chiller
I'm in the early stages of developing a class that will represent a metric
distance by storing both a number and unit (ie KM, M, CM etc).
I've developed some initial code as a starting point; however, it won't link
during a compile using VC++.
The error message I get is "
LIBCD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main
referenced in function _mainCRTStartup
Debug/Message.exe : fatal error LNK1120: 1 unresolved externals"
I've included the header and source below. Any help would be appreciated.
Thanks
//Distance.h as follows:
********************************************
#ifndef DISTANCE_H
#define DISTANCE_H
#include <iostream>
using namespace std;
class Distance
{
public :
Distance ( int, char ) ; // constructor (takes int value and string unit of
measure
~Distance ( void ) ; // destructor (its name is ~ then class name)
//access member functions
int number (void) const;
char measure (void) const;
private :
int nu ; // the value
char me ; // the unit of measure
} ;
// provide an overload of "<<" for easy display
ostream& operator<< (ostream&, const Distance&);
#endif
//Distance.cpp as follows:
******************************************************
#include "Distance.h"
#include <iostream>
using namespace std;
/*-------------------------------------------------------*\
| implementation of member functions |
\*-------------------------------------------------------*/
// constructor
Distance :: Distance ( int n, char m ) : nu(n), me(m) {}
// access functions
int Distance :: number (void) const
{
return nu;
}
char Distance :: measure (void) const
{
return me;
}
// provide an overload of "<<" for easy display
ostream& operator<< (ostream& out, const Distance& d)
{
out << d.number() << "-" << d.measure();
return out;
}
/*-------------------------------------------------------*\
| test driver for the Distance class |
\*-------------------------------------------------------*/
#ifdef TEST_DISTANCE // .... Distance class .... test driver
int main ( void )
{
// create test input
Distance a = Distance (5, KM);
cout << a << endl;
cin ignore();
return 0; // normal termination
}
#endif
distance by storing both a number and unit (ie KM, M, CM etc).
I've developed some initial code as a starting point; however, it won't link
during a compile using VC++.
The error message I get is "
LIBCD.lib(crt0.obj) : error LNK2019: unresolved external symbol _main
referenced in function _mainCRTStartup
Debug/Message.exe : fatal error LNK1120: 1 unresolved externals"
I've included the header and source below. Any help would be appreciated.
Thanks
//Distance.h as follows:
********************************************
#ifndef DISTANCE_H
#define DISTANCE_H
#include <iostream>
using namespace std;
class Distance
{
public :
Distance ( int, char ) ; // constructor (takes int value and string unit of
measure
~Distance ( void ) ; // destructor (its name is ~ then class name)
//access member functions
int number (void) const;
char measure (void) const;
private :
int nu ; // the value
char me ; // the unit of measure
} ;
// provide an overload of "<<" for easy display
ostream& operator<< (ostream&, const Distance&);
#endif
//Distance.cpp as follows:
******************************************************
#include "Distance.h"
#include <iostream>
using namespace std;
/*-------------------------------------------------------*\
| implementation of member functions |
\*-------------------------------------------------------*/
// constructor
Distance :: Distance ( int n, char m ) : nu(n), me(m) {}
// access functions
int Distance :: number (void) const
{
return nu;
}
char Distance :: measure (void) const
{
return me;
}
// provide an overload of "<<" for easy display
ostream& operator<< (ostream& out, const Distance& d)
{
out << d.number() << "-" << d.measure();
return out;
}
/*-------------------------------------------------------*\
| test driver for the Distance class |
\*-------------------------------------------------------*/
#ifdef TEST_DISTANCE // .... Distance class .... test driver
int main ( void )
{
// create test input
Distance a = Distance (5, KM);
cout << a << endl;
cin ignore();
return 0; // normal termination
}
#endif