confused using classes

Hi everyone. I'm fairly new to programming. I have an assignment on classes and I am stuck on calling one particular function.


For some reason the function is not working. Am I calling it wrong?????

OK So HERE IS MAIN.CPP

int main()
{
string fname;
cout << "\t Welcome to Target Helper \n\n";
target t; // create a new target object
char choice = ' ';

while (choice != 'Q')
{
printMenu();
cin >> choice;
// convert choice to to uppercase
choice = toupper(choice);
// ... !
switch (choice)
{
case('N') : t.newGame();
//break;
.................................................. .


My class function (implementation file) is very basic.. I just want to get it working before I add the algorithms.

So I have just done as below... it seems the problem is coming from the main.cpp file though.......??

void target::newGame(char centre, string others)
// pre : none
// post : set centre letter and other letters for a new game of target
{
cout << "Enter centre letter : ";
}

the error message showing is
no matching function for call to 'target::newGame()'
candidates are: void target::newGame(char, std::string)
[build error][puzzle.o] Error 1

Any ideas.. I have been playing around with the PC for over an hour and cant work out what I have done wrong :(
Where's the declaration of 'target'?
You need to include your target.h file in the main.cpp file (and make sure to prototype you function in it).
it is.. sorry here is the full data..

#include "target.h"
#include <fstream>
#include <iostream>
//#include <vector>

using namespace std;
void printMenu();

int main()
{
string fname;
cout << "\t Welcome to Target Helper \n\n";
target t; // create a new target object
char choice = ' ';

while (choice != 'Q')
{
printMenu();
cin >> choice;
// convert choice to to uppercase
choice = toupper(choice);
// ... !
switch (choice)
{
case('N') : t.newGame();
what do you mean to prototype my function in it??

I thought t.newGame(); was calling the function??

I'm missing something but I'm not sure what it is....
ok i worked it out I think :) dont worry
thanks for trying to help me though :-)
actually I do have another question.... how do i convert chars into a string....?

eg in the below function I have char centre which is easy.. but I have divided string others into chars.. how do I then convert the chars a, b, c, d, e, f, g and h back into one string?

void target::newGame(char centre, string others)
// pre : none
// post : set centre letter and other letters for a new game of target
{
char a, b, c, d, e, f, g, h;
cout << "Enter centre letter : ";
cin >> centre;
cout << "Enter other letters : ";
cin >> a >> b >> c >> d >> e >> f >> g >> h;
centreLetter = centre;
OMG I actually worked this one out too .. pls ignore.. :)
Topic archived. No new replies allowed.