LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 03-30-2006, 05:12 PM   #1
TurtleFace
Member
 
Registered: Jul 2005
Distribution: Mandrake LE 2005
Posts: 51

Rep: Reputation: 15
having problem with typedef


i'm trying to debug this solitaire program i wrote but i keep getting errors when i try to reference my typdef statements. i get the following errors:
Quote:
driver.cpp: In function `int main()':
driver.cpp:7: error: invalid conversion from `int' to `Card::suit'
driver.cpp:7: error: initializing argument 1 of `Card::Card(Card::suit, Card::value, Card::status)'
driver.cpp:7: error: invalid conversion from `int' to `Card::value'
driver.cpp:7: error: initializing argument 2 of `Card::Card(Card::suit, Card::value, Card::status)'
driver.cpp:7: error: invalid conversion from `int' to `Card::status'
driver.cpp:7: error: initializing argument 3 of `Card::Card(Card::suit, Card::value, Card::status)'
here is the code

Card.h:
Code:
#ifndef CARD
#define CARD
  
#include <iostream>
#include <string>
using namespace std;

typedef int suit;
typedef int value;
typedef int status;

class Card {  
	public:
		/* Class Constructor
		   pre - Card does not exist
		   post - Card exists with attributes s,v,f */
		Card(suit s, value v, status f);

		/* Copy Constructor
		   pre - original exists and is a Card object
		   post - An exact copy of original is made and returned */
		Card(const Card & original);

		/* Change status of a Card to UP
		   pre - Card exists
		   post - Card.status := FaceUp */
		void FaceUp();

		/* Change status of a Card to DOWN
		   pre - Card exists
		   post - Card.status := FaceDown */
		void FaceDown();

		/* Returns the Status of a Card
		   pre - Card exists
		   post - Card is unchanged; current status of Card is returned to user */
		Status CardStatus() const;

		/* Return the Value of a Card
		   pre - Card exists
		   post - Card is unchanged; current value of Card is returned to user */
		Value CardValue() const;

		/* Return the Suit of a Card
		   pre - Card exists
		   post - Card is unchanged; current suit of Card is returned to user */
		Suit CardSuit() const;

		/* Return the image of a Card
		   pre - Card exists
		   post - Card is unchanged; current image of card is returned to user */
		string CardImage();

		/* Sets the cards output image
		   pre - Card exists
		   post - iamge of the card has been created */
		void SetCardImage();

		/* Overloaded = operator
		   pre - Card exists
		   post - Data members are set equal to those of anotherCard */
		Card & operator = ( const Card & );

	private:
		suit mySuit;
		value myValue;
		status myStatus;
		string image;
	};
#endif
Card.cpp:
Code:
#include "Card.h"

Card::Card(suit s, value v, status f){
	mySuit = s;
	myValue = v;
	myStatus = f;
	SetCardImage();
	}

Card::Card(const Card & original){
	mySuit = original.mySuit;
	myValue = original.myValue;
	myStatus = original.myStatus;
	SetCardImage();
	}
  
void Card::FaceUp(){
	myStatus = 1;
	SetCardImage();
	}
  
void Card::FaceDown(){
	myStatus = 0;
	SetCardImage();
	}

status Card::CardStatus() const {
	return myStatus;
	}

value Card::CardValue() const {
	return myValue;
	}

suit Card::CardSuit() const {
	return mySuit;
	}
  
string Card::CardImage() {
	return image;
	}
  
void Card::SetCardImage() {
	if (CardStatus() == 1) {
		switch (CardValue()) {
			case 0: 	image = " A ";	break;
			case 1: 	image = " 2 ";	break;
			case 2: 	image = " 3 ";	break;
			case 3: 	image = " 4 ";	break;
			case 4: 	image = " 5 ";	break;
			case 5: 	image = " 6 ";	break;
			case 6: 	image = " 7 ";	break;
			case 7: 	image = " 8 ";	break;
			case 8: 	image = " 9 ";	break;
			case 9: 	image = "10 ";	break;
			case 10:	image = " J ";	break;
			case 11:	image = " Q ";	break;
			case 12:	image = " K ";	break;
			}

		switch (CardSuit()) {
			case 0: 	image + "H";	break;
			case 1: 	image + "C";	break;
			case 2: 	image + "D";	break;
			case 3: 	image + "S"; 	break;
			}
		}
	else if (CardStatus() == 0) {
		image = "XXXX" ;
		}
	else {
		image = "NONE" ;
		}
	}

Card & Card::operator = (const Card & anotherCard) {
	myStatus = anotherCard.myStatus;
	myValue = anotherCard.myValue;
	mySuit = anotherCard.mySuit;
	SetCardImage();
	return * this;
	}
driver.cpp:
Code:
#include "Card.h"

int main() {
	Card temp(0, 0, 1);
	cout << temp.CardImage();
	return 0;
	}
i know the problem is something simple i just can't figure it out. all help is appreciated.
 
Old 03-30-2006, 05:26 PM   #2
cupubboy
Member
 
Registered: May 2003
Location: Bucharest,Romania
Distribution: Fedora Core 7
Posts: 109

Rep: Reputation: 15
Might me a compiler issue .. I can't see really what's wrong .. I'll try to replicate this behaviour in a minute ..

Also have you considered using enums ? they sound more appropriate

-- Later edit:
You also have an error
remember that your code is case sensitive
you have: typedef int value;

but then you use:
Value CardValue() const;

it should be "value" not "Value" (same thing for Status and Suit in your Card.h)

After modifying Card.h (on my windows box .. with gcc 3.4.2 (mingw)) .. everything compiled and worked

Last edited by cupubboy; 03-30-2006 at 05:33 PM.
 
Old 03-30-2006, 06:02 PM   #3
TurtleFace
Member
 
Registered: Jul 2005
Distribution: Mandrake LE 2005
Posts: 51

Original Poster
Rep: Reputation: 15
i made the changes but i still get the same errors. so i just have problems with my compiler?
 
Old 03-30-2006, 07:12 PM   #4
cupubboy
Member
 
Registered: May 2003
Location: Bucharest,Romania
Distribution: Fedora Core 7
Posts: 109

Rep: Reputation: 15
I think I read somewhere about a certain version of g++ havin problems with typedefs .. but I'm not sure .. what version are you using?

In about one hour or so .. I'll finish here and reboot into linux and also try there .. like I said .. on Windows with gcc 3.4.2 it compiles perfectly after the changes in Card.h
 
Old 03-30-2006, 09:18 PM   #5
cupubboy
Member
 
Registered: May 2003
Location: Bucharest,Romania
Distribution: Fedora Core 7
Posts: 109

Rep: Reputation: 15
Update:
I've just compiled it under CentOs 4.2 with g++ (GCC) 3.4.4 20050721 (Red Hat 3.4.4-2) with just the 3 modifications on Card.h
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
a question regarding typedef erikash Programming 1 11-10-2005 04:37 AM
Can you help me with typedef? brownstone Programming 3 06-11-2004 10:09 AM
Typedef Problem in GCC in Linux ashwinipahuja Programming 4 04-26-2004 03:14 AM
explanation on typedef naren Programming 5 03-09-2004 10:48 PM
sizeof my typedef... jhorvath Programming 7 10-11-2002 05:41 PM


All times are GMT -5. The time now is 04:56 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration