sry again, i am still learning classes :( folllowing is a new class than my previous post
header file:
Code:
#ifndef __cDATE_H
#define __cDATE_H
#include <iostream.h>
class cSTRING
{
private:
int nCmpValue;
char *_name;
public:
cSTRING(char *name, int returnVal);
cSTRING(cSTRING &rhs);
cDATE(int,int);
~cSTRING();
char *getName()
{
return _name;
}
void two(char*,int);
cSTRING& operator=(const cSTRING& cStr);
cSTRING operator+(const cSTRING& cStr);
cSTRING& operator+=(const cSTRING& cStr);
cSTRING& operator==(const cSTRING& cStr);
cSTRING& operator!=(const cSTRING& cStr);
};
#endif
CPP File:
Code:
#include "cDATE.h"
#include <iostream.h>
#include <string.h>
cSTRING::cSTRING(char *name, int returnVal)
{
nCmpValue = returnVal;
_name = new char[strlen(name) + 1];
//Allocates an character array object
strcpy(_name, name);
cout << "cSTRING Default Constructor Called" << endl;
}
cSTRING& cSTRING::operator=(const cSTRING& other)
{
cout << "cSTRING assignment op" << endl;
if (this!=&other)
{
}
return *this;
}
cSTRING cSTRING::operator+(const cSTRING& d)
{
cSTRING d1;
cout << "inside +" << endl;
return( d1 );
}
cSTRING::cSTRING(cSTRING &rhs)
{
_nCmpValue = rhs.getId();
_name = new char[strlen(rhs.getName()) + 1];
strcpy(_name,rhs._name);
}
cSTRING::~cSTRING()
{
delete[] _name;
cout << "Destructor called" << endl;
};
Driver file:
Code:
#include "cDATE.h"
#include <iostream.h>
//cSTRING doNothing1( cSTRING d );
//void doNothing2( const cSTRING& d );
int main(void)
{
char mychar = 'h';
cout << "Hello called ";
// cSTRING d1(mychar);
cout << endl;
cSTRING programmer("John",22);
cout << programmer.getName() << endl;
return (0);
}
this program is *suppose* to create a dynamic string, use operators to add two strings, numbers, and check if they are ==
i am kinda stuck and have been using this wonderful tutorial @ about.com
errors:
Debug/console api.exe : fatal error LNK1120: 1 unresolved externals
it builds but doesnt link i guess