hi guys,

i've been battling with this program for too long now... i cant seem to get it to compile. i believe the problem lies in my use of objects being passed to different classes as parameters.

(i will do my best to only paste code that i believe is causing the issues. if more is needed, let me know.)

the program is a typing tutor... i created a superclass, difficultyLvl.h, to contain all the variables and a declaration of 3 virtual functions:

// Procedural functions
		virtual string wordList() = 0;	// random word list virtual method
		virtual void gameEvent(gameSequence &pobjSequence) = 0;	// game logic for coward difficulty level virtual method
		virtual void gameConsole(gameSequence &pobjSequence) = 0;	// game console virtual method
		// End procedural functions

from this i have two subclasses, gui.h (containing console ascii art), and gameSequence.h, containing the main game method.

the object is declared in main, as it should be:

//**********Object Declarations**************
	gameSequence objSequence(0, "XXXXX", "", "", "Start", "           ", 0, "             ");
	difficultyLvl * pobjSequence = &objSequence;	// Declare the main object to drive gameSequence/difficultyLvl classes
	gui objVisuals;	// declare the visuals object to display gui methods from main
	Wpm wpm;	// declare wpm object
	difficultySelection objDifSelection;		// object to drive difficulty selection menu
	//**********End Object Declarations**********

and, this is where i believe the trouble hits. I need to then pass this object to the subclasses to opperate off of. this is how i launch my main game sequence from main:

//**************** LAUNCH THE MAIN GAME DRIVER METHOD ****************
		pobjSequence->gameEvent(pobjSequence);	// launch game sequence
		//**************** END LAUNCH THE MAIN GAME DRIVER METHOD ************

i also, later in main, request the gui.h class to display the gameOver console using this object to display the results:

objVisuals.gameOver(gameSequence &pobjSequence);						// display game over screen

in the next post i will display my gui.h and gameSequence.h header files...

here is gui.h:

#ifndef GUI_H
#define GUI_H

#include "gameSequence.h"
#include "difficultyLvl.h"

class gameSequence;


using namespace std;

//Wpm Class Declaration
class gui{
	private:
		int difficulty;			//difficulty selection
	public:
		// **************GUI METHODS********************
		void welcomeMenu(); 	// Intro Screen Welcome Message
		void goodBye(); 	// Exit Program Screen Message
		void consoleEasy(gameSequence &pobjSequence);	// coward dashboard
		void consoleMedium(gameSequence &pobjSequence);	// w. adversary dashboard
		void consoleHard(gameSequence &pobjSequence);	// s. master dashboard
		void gameOver(gameSequence &pobjSequence);	// game over dashboard
		void victoryScreen(gameSequence &pobjSequence);	// victory dashboard
		// **************END GUI METHODS****************

		// **************SET / GET METHODS *************
		void setDifficulty(int);			//set the difficulty to determine which random set to access
		int getDifficulty(){return difficulty;}	// get difficulty value - used with getrandword
		// **************END SET / GET METHODS *********


};
#endif

and here is gamesequence.h:

#ifndef GAMESEQUENCE_H
#define GAMESEQUENCE_H

//**********Include Statements**********
#include <iostream>	  //input output stream function
#include <string>	  //String function
#include <cstdlib>    //Random function
#include <ctime>      //Time function
#include <iomanip>	  //Used with random
#include <fstream>	  //Used to initiate the file stream function
#include "difficultyLvl.h"	// superclass reference
#include "wpm.h"	// calculates words per minute
#include "gui.h"	  // contains interface gui screens
#include "topscore.h"		//Class topscore header file
using namespace std;
//**********End Include Statements**********



class gameSequence : public difficultyLvl{
	private:
		string strInput;
	public:
		// Constructor functions
		gameSequence();	// empty constructor to set values to zero
		gameSequence(int, string, char [7], string, string, string, int, string);	// accepts values for centerX, centerY, and radius. Should call the overridden calcArea function
		// End Constructor functions

		// Procedural functions
		string wordList();	// return random word from list function
		void gameEvent(gameSequence &pobjSequence);	// main game logic
		void gameConsole(gameSequence &pobjSequence);	// coward difficulty game console
		// End procedural functions

		void wait4user();									// Function to prompt before program exit

		friend class Wpm;						//Set wpm as a friend class

};

gameSequence::gameSequence(){	// constructor to set all values to defaults
		setScore(0);
		setLives("XXXXX");
		setLevel("");
		setMessage("");
		setWord("Start");
		setSpaces("           ");
		setWrong(0);
		setRank("             ");
}

gameSequence::gameSequence(int sc, string liv, char l[7], string m, string wrd, string sp, int wrng, string r){	// overloaded constructor to assign values
		score = sc;
		lives = liv;
		for(int i = 0; i < 7; i++){level[i] = l[i];}
		message = m;
		word = wrd;
		spaces = sp;
		wrong = wrng;
		rank = r;
}

#endif

i believe i'm deffinitely doing something wrong the way i'm passing around this object. My thoughts are that the way they are being passed is perhaps as a new object declaration versus the original object...

i'm thinking that must be the case, because i got the following link errors when i commented out the lines of code generating compilation errors:

1>difficultySelection.obj : error LNK2005: "public: __thiscall difficultySelection::difficultySelection(void)" (??0difficultySelection@@QAE@XZ) already defined in TypingTutorMain.obj
1>difficultySelection.obj : error LNK2005: "public: __thiscall difficultySelection::difficultySelection(void)" (??0difficultySelection@@$$FQAE@XZ) already defined in TypingTutorMain.obj
1>gameSequence.obj : error LNK2005: "public: __thiscall gameSequence::gameSequence(void)" (??0gameSequence@@QAE@XZ) already defined in TypingTutorMain.obj
1>gameSequence.obj : error LNK2005: "public: __thiscall gameSequence::gameSequence(int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,char * const,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0gameSequence@@QAE@HV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAD000H0@Z) already defined in TypingTutorMain.obj
1>gameSequence.obj : error LNK2005: "public: __thiscall gameSequence::gameSequence(void)" (??0gameSequence@@$$FQAE@XZ) already defined in TypingTutorMain.obj
1>gameSequence.obj : error LNK2005: "public: __thiscall gameSequence::gameSequence(int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,char * const,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0gameSequence@@$$FQAE@HV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAD000H0@Z) already defined in TypingTutorMain.obj
1>gui.obj : error LNK2005: "public: __thiscall gameSequence::gameSequence(void)" (??0gameSequence@@QAE@XZ) already defined in TypingTutorMain.obj
1>gui.obj : error LNK2005: "public: __thiscall gameSequence::gameSequence(int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,char * const,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0gameSequence@@QAE@HV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAD000H0@Z) already defined in TypingTutorMain.obj
1>gui.obj : error LNK2005: "public: __thiscall gameSequence::gameSequence(void)" (??0gameSequence@@$$FQAE@XZ) already defined in TypingTutorMain.obj
1>gui.obj : error LNK2005: "public: __thiscall gameSequence::gameSequence(int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,char * const,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0gameSequence@@$$FQAE@HV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAD000H0@Z) already defined in TypingTutorMain.obj
1>difficultySelection.obj : error LNK2028: unresolved token (0A0002B0) "public: int __thiscall difficultySelection::difficultyLevel(void)" (?difficultyLevel@difficultySelection@@$$FQAEHXZ) referenced in function "[T2M] public: __thiscall std::bad_alloc::bad_alloc(class std::bad_alloc const &)" (__t2m@??0bad_alloc@std@@QAE@ABV01@@Z)
1>TypingTutorMain.obj : error LNK2028: unresolved token (0A00031C) "public: int __thiscall difficultySelection::difficultyLevel(void)" (?difficultyLevel@difficultySelection@@$$FQAEHXZ) referenced in function "public: __thiscall difficultySelection::difficultySelection(void)" (??0difficultySelection@@$$FQAE@XZ)
1>TypingTutorMain.obj : error LNK2019: unresolved external symbol "public: int __thiscall difficultySelection::difficultyLevel(void)" (?difficultyLevel@difficultySelection@@$$FQAEHXZ) referenced in function "public: __thiscall difficultySelection::difficultySelection(void)" (??0difficultySelection@@$$FQAE@XZ)
1>difficultySelection.obj : error LNK2001: unresolved external symbol "public: int __thiscall difficultySelection::difficultyLevel(void)" (?difficultyLevel@difficultySelection@@$$FQAEHXZ)
1>TypingTutorMain.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall gameSequence::wordList(void)" (?wordList@gameSequence@@UAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>gameSequence.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall gameSequence::wordList(void)" (?wordList@gameSequence@@UAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>gui.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall gameSequence::wordList(void)" (?wordList@gameSequence@@UAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>TypingTutorMain.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall gameSequence::gameConsole(class gameSequence &)" (?gameConsole@gameSequence@@UAEXAAV1@@Z)
1>gameSequence.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall gameSequence::gameConsole(class gameSequence &)" (?gameConsole@gameSequence@@UAEXAAV1@@Z)
1>gui.obj : error LNK2019: unresolved external symbol "public: virtual void __thiscall gameSequence::gameConsole(class gameSequence &)" (?gameConsole@gameSequence@@UAEXAAV1@@Z) referenced in function "[T2M] public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall difficultyLvl::getSpaces(void)" (__t2m@?getSpaces@difficultyLvl@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>H:\School\Spring 2009\297 c++\Final_Project\Henzel_FinalProject_CSIS297\Debug\Henzel_FinalProject_CSIS297.exe : fatal error LNK1120: 5 unresolved externals
1>Build log was saved at "file://h:\School\Spring 2009\297 c++\Final_Project\Henzel_FinalProject_CSIS297\Henzel_FinalProject_CSIS297\Debug\BuildLog.htm"

as it stands now, here are the 3 compilatin errors i'm getting:

1>.\gameSequence.cpp(191) : error C2275: 'gameSequence' : illegal use of this type as an expression
1>.\TypingTutorMain.cpp(95) : error C2664: 'difficultyLvl::gameEvent' : cannot convert parameter 1 from 'difficultyLvl *' to 'gameSequence &'
1>.\TypingTutorMain.cpp(120) : error C2275: 'gameSequence' : illegal use of this type as an expression
1>        g:\school\spring 2009\297 c++\final_project\henzel_finalproject_csis297\henzel_finalproject_csis297\gameSequence.h(20) : see declaration of 'gameSequence'

any guidance will be very much appreciated! i've been at this for 16 hours straight yesterday, and am almost at the end of my ropes here!

ok i made a few slight adjustments, and i thought i would post the updated code... still giving link errrors, but i feel i'm closer to the solution:

ok, so heres what i got. i'll just track the class object, as thats obviously the problem i'm having.

TypingTutorMain.cpp (contains main() ):

//**********Object Declarations**************
	gameSequence objSequence(0, "XXXXX", "", "", "Start", "           ", 0, "             ");
	difficultyLvl * pobjSequence = &objSequence;	// Declare the main object to drive gameSequence/difficultyLvl classes
	gui objVisuals;	// declare the visuals object to display gui methods from main
	Wpm wpm;	// declare wpm object
	difficultySelection objDifSelection;		// object to drive difficulty selection menu
	//**********End Object Declarations**********

now that the object is declared, and re-declared as a pointer to the subclass derived from the suerclass (named pobjSequence), i proceed to use it to call my classes as a parameter reference:

//**************** LAUNCH THE MAIN GAME DRIVER METHOD ****************
		pobjSequence->gameEvent(*pobjSequence);	// launch game sequence
		//**************** END LAUNCH THE MAIN GAME DRIVER METHOD ************

the other occurrence in main is where i call my endgame panel from the objectVisuals object (declared in the object declaration block above in main):

objVisuals.gameOver(*pobjSequence);						// display game over screen

now that thats declared, i'll show you where its going...

the difficultyLvl.h class is used as a superclass to declare virtual methods to be re-used in my subclasses. i pass the objects to a couple of these methods like this:

// Procedural functions
		virtual string wordList() = 0;	// random word list virtual method
		virtual void gameEvent(difficultyLvl & pobjSequence) = 0;	// game logic for coward difficulty level virtual method
		virtual void gameConsole(difficultyLvl & pobjSequence) = 0;	// game console virtual method
		// End procedural functions

inside my subclass, gameSequence.h, they are implemented:

void gameEvent(difficultyLvl & pobjSequence);	// main game logic
		void gameConsole(difficultyLvl & pobjSequence);	// coward difficulty game console

passed to the method inside the class:

void gameSequence::gameEvent(difficultyLvl & pobjSequence){	// game logic for coward difficulty level

and then used:

pobjSequence.gameConsole(pobjSequence);				// call the difficulty screen

the gui.h - which is used to display ascii art visuals with the object's data inclusions:

#ifndef GUI_H
#define GUI_H

#include "gameSequence.h"
#include "difficultyLvl.h"

class gameSequence;


using namespace std;

//Wpm Class Declaration
class gui{
	private:
		int difficulty;			//difficulty selection
	public:
		// **************GUI METHODS********************
		void welcomeMenu(); 	// Intro Screen Welcome Message
		void goodBye(); 	// Exit Program Screen Message
		void consoleEasy(difficultyLvl & pobjSequence);	// coward dashboard
		void consoleMedium(difficultyLvl & pobjSequence);	// w. adversary dashboard
		void consoleHard(difficultyLvl & pobjSequence);	// s. master dashboard
		void gameOver(difficultyLvl & pobjSequence);	// game over dashboard
		void victoryScreen(difficultyLvl & pobjSequence);	// victory dashboard
		// **************END GUI METHODS****************

this is being passed to the functions located in gui.cpp (resource file) as such:

void gui::victoryScreen(difficultyLvl & pobjSequence){	// victory dashboard

and being utilized inside those methods as:

cout << " |||| Score:  " << pobjSequence.getScore() << "  |||||| Lives: " << pobjSequence.getLives() << " |||||| Level: " << pobjSequence.getLevel() << " ||||\n"; 		// get vals from structure

I know there is a lot going on here as i have so many references, but i believe its all tied down to one overlaying mis-use of the object. That MUST be how the link errors are occurring, right?

If you could shed any light on my link error issues, it would be totally apprecaited!

currently doing a lot of research in to link errors... i'm really not sure what is giving me the trouble though.

It seems to be a problem with the objects declared, but its impossible to tell where the trouble is hitting given the link errors dont even tell me what file the problem is happening in...

I have no idea how i'm going to get beyond this w/o help... link error definitions on the web are so general and un-related to the problem i'm having...

Probably you place class implementations in .h files (at least for gameSequence and difficultySelection classes). That's why you have gameSequence.obj object module (see diagnostics in OP), for example (correct .h files w/o implementation codes are never produced object modules). Of course, after that you have these classes implementation in every module where .h file is included - and the linker reports errors ("...already defined...").

Remember: .h files contain only class definitions or inline functions. Place all member functions implementations into separate .cpp file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.