Help with this code for my project

Errors when I try to run my code

Page 1 of 1

4 Replies - 1866 Views - Last Post: 10 November 2008 - 12:23 PM Rate Topic: -----

#1 Winterhawk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 15-July 08

Help with this code for my project

Post icon  Posted 08 November 2008 - 04:32 PM

This the errors that I am getting:error C2511: 'void Controller::start(char,char)' : overloaded member function not found in 'Controller'; error C2511: 'void Dictionary::addWord(int,int,std::string,int,int)' : overloaded member function not found in 'Dictionary'; error C2511: 'void Dictionary::getWord(std::string,char [],int &)' : overloaded member function not found in 'Dictionary'

Here is my code for the project:

Controller.cpp
#include <iostream>
#include "Controller.h"

using namespace std;

void Controller::start(char word,char inChar)
{
	
   //	 
	   
}




Controller.h
#ifndef Controller_h
#define Controller_h

#include "Dictionary.h"


class Controller:public Dictionary
{
	private:
		string filename; // stores name of file where words are stored
	public:
		Controller();	//default constructor
		void getWord(string w);// Add accessor and mutator methods here for your member values
		void setWord(string w);
		void start();
		 Dictionary myDictionary;
		
};
#endif




Dictionary.cpp
#include <iostream>
#include "Dictionary.h"
#include <fstream>

using namespace std;



void Dictionary::addWord(int MAX_WORD_SIZE, int Count, string Word, int Size, int Words)
{
	{
	myGame.loadFile();
	ofstream outData("words.txt");
	try
	{
	cout << "\tEnter a new word, keep it below " << MAX_WORD_SIZE << " characters: ";
	cin >> Word;
		 Size  = strlen(Word);
	if(Size == 0 || Size > MAX_WORD_SIZE)
		throw Word;

		  strcpy_s(Words[Count++],MAX_WORD_SIZE,Word);

		  for (int i = 0; i < Count; ++i) 
			 Datfile << Words[i] << endl;
	}
	catch (int word)
	{
		cout << "An error was found incorrect key entered\n";
	}
	}
}


void Dictionary::deleteWord()
{
	//
}


void Dictionary::findWord()
{
	//
}


void Dictionary::getWord(string skipWord, char hmWord[], int & letAmount)
{
	ifstream inData; 
	int randNum;  // local variable that will be used to randomize which word
				  // gets pick.

	srand( GetTickCount() ); // seeds are randomizer

	randNum = rand()%11; // assigns "randNum" to a random number 0 - 11

	while( (randNum < 1) || (randNum > 10) ) // This for loop makes sure that "randNuM"
		randNum = rand()%11;				 // stay's between 1 - 10

	inData.open("words.txt"); // open's up "words.txt"

	for(int i = 0; i < randNum; i++) // a for loop that reads through the words list
	{								 // and skips over the words that aren't in the location of
		outData >> skipWord;			 // where are "randNum" stops at.
	}

	outData >> hmWord; // reads in the random word and stores in "hmWord[]"

	outData.close(); // closes file
	

	letAmount = strlen(hmWord);
}



Dictionary.h
#ifndef Dictionary_h
#define Dictionary_h

#include <string>


using namespace std;

class Dictionary 
{

public:

   void addWord();	

   void deleteWord();

   void findWord();
 
   void getWord();

   string words;

   

   
	
};
#endif




Main.cpp
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include "Controller.h"
#include "Dictionary.h"



using namespace std;

int main ()
{
   
	

	string word;
	char inChar;

	Dictionary myDictionary;
		
	
	Controller myController;
	void Start();

	return 0;
}




I hope that someone can help me out with this.

Is This A Good Question/Topic? 0
  • +

Replies To: Help with this code for my project

#2 GWatt  Icon User is offline

  • member icon

Reputation: 307
  • View blog
  • Posts: 3,105
  • Joined: 01-December 05

Re: Help with this code for my project

Posted 08 November 2008 - 05:26 PM

All of your errors are because the function declaration and function definitions don't match.
//declaration
void start();
//definition
void Controller::start(char word,char inChar)



functions must accept the same signature in their declaration and definition.
Was This Post Helpful? 0
  • +
  • -

#3 Winterhawk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 15-July 08

Re: Help with this code for my project

Posted 09 November 2008 - 03:21 PM

View PostGWatt, on 8 Nov, 2008 - 04:26 PM, said:

All of your errors are because the function declaration and function definitions don't match.
//declaration
void start();
//definition
void Controller::start(char word,char inChar)



functions must accept the same signature in their declaration and definition.


Quote

I made some changes to my code and this is what I have as of now.
: dictionary.cpp(13) : error C2761: 'void Dictionary::loadFile(void)' : member function redeclaration not allowed
dictionary.cpp(15) : error C2065: 'open' : undeclared identifier
dictionary.cpp(15) : error C2228: left of '.inData' must have class/struct/union
dictionary.cpp(20) : error C2664: 'strlen' : cannot convert parameter 1 from 'std::string' to 'const char *'
dictionary.cpp(24) : error C2109: subscript requires array or pointer type
dictionary.cpp(27) : error C2109: subscript requires array or pointer type
dictionary.cpp(33) : fatal error C1506: unrecoverable block scoping error



Controller.cpp
#include <iostream>
#include "Controller.h"

using namespace std;

void Controller::start(char word,char inChar)
{
	
   //	 
	   
}



Controller.h
#ifndef Controller_h
#define Controller_h

#include "Dictionary.h"


class Controller:public Dictionary
{
	private:
		string filename; // stores name of file where words are stored
	public:
		Controller();	//default constructor
		void getWord(string w);// Add accessor and mutator methods here for your member values
		void setWord(string w);
		void addWord();	
		void deleteWord();
		void findWord();
		void Controller::start(char word,char inChar); 
		void start(); 


		Dictionary myDictionary;
		
};
#endif




Dictionary.h
#ifndef Dictionary_h
#define Dictionary_h

#include <string>


using namespace std;

class Dictionary 
{

public:

   void addWord(int MAX_WORD_SIZE, int Count, string Word, int Size, int Words);	
   void deleteWord();
   void findWord();
   void getWord(string skipWord, char hmWord[], int & letAmount);
   string words;
   Dictionary();
   void Dictionary::loadFile();
   
	
};
#endif




Dictionary.cpp
#include <iostream>
#include "Dictionary.h"
#include "Controller.h"
#include <fstream>

using namespace std;



void Dictionary::addWord(int MAX_WORD_SIZE, int Count, string Word, int Size, int Words)
{
	{
	void Dictionary::loadFile("words.txt");

	open.inData("words.txt");
	try
	{
	cout << "\tEnter a new word, keep it below " << MAX_WORD_SIZE << " characters: ";
	cin >> Word;
		 Size  = strlen(Word);
	if(Size == 0 || Size > MAX_WORD_SIZE)
		throw Word;

		  strcpy_s(Words[Count++],MAX_WORD_SIZE,Word);

		  for (int i = 0; i < Count; ++i) 
			 inData << Words[i] << endl;
	}
	catch (int word)
	{
		cout << "An error was found incorrect key entered\n";
	}
	}
}


void Dictionary::deleteWord()
{
	//
}


void Dictionary::findWord()
{
	//
}


void Dictionary::getWord(string skipWord, char hmWord[], int & letAmount)
{
	ifstream inData; 
	int randNum;  // used to randomize which word
				  // gets pick.

	

	randNum = rand()%11; // assigns "randNum" to a random number 0 - 11

	while( (randNum < 1) || (randNum > 10) ) // This loop makes sure that "randNuM"
		randNum = rand()%11;				 // stay's between 1 - 10

	inData.open("words.txt"); // open's up "words.txt"

	for(int i = 0; i < randNum; i++) // a for loop that reads through the words list
	{								 // and skips over the words that aren't in the location of
		outData >> skipWord;			 // where are "randNum" stops at.
	}

	outData >> hmWord; // reads in the random word and stores in "hmWord[]"

	outData.close("Words.txt"); // closes file
	

	letAmount = strlen(hmWord);
}



Main.cpp
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include "Controller.h"
#include "Dictionary.h"



using namespace std;

int main ()
{
   
	

	string word;
	char inChar;

	
		
	
	Controller myController;
	void Start();

	return 0;
}




[b]Thanks for any help that is given.[/quote]
Was This Post Helpful? 0
  • +
  • -

#4 GWatt  Icon User is offline

  • member icon

Reputation: 307
  • View blog
  • Posts: 3,105
  • Joined: 01-December 05

Re: Help with this code for my project

Posted 09 November 2008 - 03:32 PM

In the addWord function of the Dictionary.cpp file:

Quote

void Dictionary::loadFile("words.txt");

You only use that syntax (returnType Class::function() ) when you're defining a function. When you're trying to call the function the syntax is like this:
object.function()


However, since the loadFile function you're calling is part of the same class as the addWord function you don't need to have the object reference. You can just say loadFile()

Also in your Dictionary.h file

Quote

void Dictionary::loadFile()

You don't need the Dictionary:: part, just the void and loadFile(). also, you need to specify a parameter since you call the loadFile function with a string.
Was This Post Helpful? 0
  • +
  • -

#5 StephenIsienyi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 10-November 08

Re: Help with this code for my project

Posted 10 November 2008 - 12:23 PM

For Software Engineering Best Practices' sake:

make sure of the following:

1) an accessor function returns the content of the class member it accesses - it should not be a void function.
- for example:
char * Controller::get_Word()
{
return Word; // a string data member named Word
}

2) Because the Controller class is derived from the Dictionary class, there is no need to have a Dictionary object within the Controller class. In other words, the Controller class is a Dictionary class, and so therefore does not need a Dictionary object within it.

3) Lastly, always keep your data members private, and only deal with them using accessor/mutator methods if you need to do so outside of their class.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1