C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 19th, 2006, 03:56 PM
Beginner101 Beginner101 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 2 Beginner101 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 57 sec
Reputation Power: 0
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=====================

Reply With Quote
  #2  
Old March 23rd, 2006, 11:12 PM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
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
is wrong. It should be corrected to
Code:
char * newAddress = NULL
.

Reply With Quote
  #3  
Old March 25th, 2006, 01:16 AM
Beginner101 Beginner101 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 2 Beginner101 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 57 sec
Reputation Power: 0
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()
{

}

Reply With Quote
  #4  
Old March 25th, 2006, 03:46 PM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 4
Send a message via AIM to Geo.Garnett
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Creating a Class


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT