User Name
Password

Go Back   Planetarion Forums > Non Planetarion Discussions > Programming and Discussion
Register FAQ Members List Calendar Arcade Today's Posts

Reply
Thread Tools Display Modes
Unread 25 Oct 2002, 13:23   #1
Iniluki
Baron Samedi
 
Join Date: May 2001
Location: I'm not idimmu
Posts: 62
Iniluki has a spectacular aura aboutIniluki has a spectacular aura aboutIniluki has a spectacular aura about
Help with C++ classes.

Code:
/* 3. Modify 2. Such that the constructor is overloaded to take 2 parameters
of type char pointer.  Use these parameters to initialise the private members.
 This constructor should also be in-line as in question 2.
Create 2 objects by using both constructors.  Output the two default sets of details
then modify them with the member functions and output the new values */


#include <iostream.h>
#include <stdio.h>

class TShape
{
private:
char* itsColour;
char* itsShape;

public:

void SetColour(char* pColour);
void SetShape(char* pShape);
void SetColour(void); 
void SetShape(void); 
char* GetColour(void); 
char* GetShape(void);
TShape(void) {itsShape ="Square"; itsColour="Red";}; 
TShape(char* pColour, char* pShape);

}; //end TShape Class

//Private data access function to set data
void TShape::SetColour(char* pColour)
{
itsColour = pColour;
}

//private data access function to set data

void TShape::SetShape(char* pShape)
{
itsShape = pShape;
}

//private data access function to get data

char* TShape::GetColour(void)
{
return itsColour;   
}

//private data access function to get data

char* TShape::GetShape(void)
{
return itsShape;  
}

inline TShape::TShape(char* pColour, char* pShape)
{
	itsShape = pShape;
	itsColour = pColour;
}






void main()
{
TShape obj1("Green","Octagon"),
       obj2(),
	   obj3;


cout<<"Object 1 is a "<< obj1.GetColour()<<" "<< obj1.GetShape() <<" \n";
cout<<"Object 2 is a "<< obj2.GetColour()<<" "<< obj2.GetShape() <<" \n";

obj1.SetColour("Purple");
obj1.SetShape("Egg");

cout<<"Object 3 is a "<< obj3.GetColour()<<" "<< obj3.GetShape() <<" \n";

getchar();
    
}

The 2 errors i get are

\classes\classes3.cpp(76) : error C2228: left of '.GetColour' must have class/struct/union type

and

\classes\classes3.cpp(76) : error C2228: left of '.GetShape' must have class/struct/union type



__________________

Victims, aren't we all?
Iniluki is offline   Reply With Quote
Unread 25 Oct 2002, 13:25   #2
Iniluki
Baron Samedi
 
Join Date: May 2001
Location: I'm not idimmu
Posts: 62
Iniluki has a spectacular aura aboutIniluki has a spectacular aura aboutIniluki has a spectacular aura about
nm i fixed it.

me == teh silly
__________________

Victims, aren't we all?
Iniluki is offline   Reply With Quote
Unread 25 Oct 2002, 13:29   #3
Cocaine
Guest
 
Posts: n/a
I demand u give me your course work assignments so I can learn C++ properly rather than teach myself crap.

ok Idi ?
  Reply With Quote
Unread 25 Oct 2002, 13:38   #4
Iniluki
Baron Samedi
 
Join Date: May 2001
Location: I'm not idimmu
Posts: 62
Iniluki has a spectacular aura aboutIniluki has a spectacular aura aboutIniluki has a spectacular aura about
Quote:
Originally posted by Cocaine
I demand u give me your course work assignments so I can learn C++ properly rather than teach myself crap.

ok Idi ?


hmm
im a peer tutor for the first years. There first assignment comes out in a few weeks. I'll let you have that.

You'll have to be able to do. While, do while and for loops. File input. And if statements. :P
__________________

Victims, aren't we all?
Iniluki is offline   Reply With Quote
Unread 25 Oct 2002, 14:09   #5
MT
/dev/zero
Retired Mod
 
MT's Avatar
 
Join Date: May 2000
Posts: 415
MT is an unknown quantity at this point
Quote:
Originally posted by Cocaine
I demand u give me your course work assignments so I can learn C++ properly rather than teach myself crap.

ok Idi ?
I want to oppress you.
__________________
#linux : Home of Genius

<idimmu> ok i was chained to a desk with this oriental dude
MT is offline   Reply With Quote
Unread 25 Oct 2002, 21:14   #6
Cocaine
Guest
 
Posts: n/a
Quote:
Originally posted by MT


I want to oppress you.
:/
  Reply With Quote
Reply



Forum Jump


All times are GMT +1. The time now is 00:13.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2018