| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Creating a Class
I'm working on a class that allows me to input a few variables and create a HTML link (<A> tag) however I've run into a couple of bugs I cannot pin down. I'm rather new at C++ and this is my first attempt at developing a custom class but I'm familiar with the concepts behind the class.
Code:
#include <iostream>
#include <conio>
class CWebLink {
public:
CWebLink::~CWebLink(
char *newAddress = 0,
*newDomain = 0,
*newDisplayText =0);
private:
char *pWebLink,
*pAddress,
*pDomain,
*pDisplayText;
//====================Copy Constructor================
CWebLink( CWebLink&);
//====================Deconstructor================= =====
CWebLink::~CWebLink();
//====================Points to the <a> string=================
char* GetLink();
void SetAddress(char*);
void SetDomain(char*);
void SetDisplayText(char*);}
//======================Overload Function=================
CWebLink& operator=(CWebLink&);
};
//========================End Class=====================
|
|
#2
|
|||
|
|||
|
Though I have not read your complete code, but can spot one major bug.
You initialize a pointer ( by deault) by placing NULL instead of 0 as you have done. that is Code:
char* newAdress = 0 Code:
char * newAddress = NULL |
|
#3
|
|||
|
|||
|
I have the class working properly (I think) but I'm failing on getting the class to display the link properly.
Code:
#include <iostream>
#include <conio.h>
using std::cout;
using std::endl;
class CWebLink
{
private:
char *pWebLink,
*pAddress,
*pDomain,
*pDisplayText;
public:
CWebLink(char *newAddress=NULL,
char *newDomain=NULL,
char *newDisplayText=NULL);
CWebLink(const CWebLink&);
CWebLink::~CWebLink();
const char * GetLink() const;
void SetAddress(char*);
void SetDomain(char*);
void SetDisplayText(char*);
CWebLink& operator=(const CWebLink&);
};
int main()
{
}
|
|
#4
|
||||
|
||||
|
Yes good one beginner, the main thing to remember is not to initialize values for your variables inside the class, that is the constructors job.
Such as Code:
CWebLink::CWebLink()//constructor
{
//this is were you would give values to those variables
pWeblink = 0;
//etc.
}
Another alternative is to make a function to declare the default values rather than doing so in the constructor. A good resource for class tutorials link
__________________
---Official Member Of The Itsacon Fan Club--- ![]() Give a man a fish and he will eat for a day. Teach a man to fish and he will sit in a boat all day drinking beer. Last edited by Geo.Garnett : March 25th, 2006 at 03:50 PM. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Creating a Class |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|