0

Im getting the folowing error while trying to implement a friend function between two classes.

"Board.C: In member function ‘void Board::input(bool)’:
Board.C:227: error: ‘class Piece’ has no member named ‘castSpell’
make: *** [Board.o] Error 1"

Piece's Header file

#ifndef PIECE_H
#define PIECE_H
# include "Spellcaster.h"
# include <iostream>
#include <string>
#include<cmath>


using namespace std;
class Board;


class Piece
{
public:
	string name;
	bool Player;
	Piece();
	~Piece(){};
	virtual bool validMove (int,int)=0;
	virtual void move (int x, int y ){};
	string symbol;
	int xPos;
	int yPos;
	void setLife(int);
	int getLife();
	void Select();
	void takeDamage(int);
	bool caster;
	bool secondaryAction;
	friend void Spellcaster::castSpell();
private:
	
	int life;

};

It has to use the function castSpell() from SpellCaster.h

#ifndef SPELLCASTER_H
#define SPELLCASTER_H
#include "Piece.h"
#include<iostream>
using namespace std;



class Spellcaster
{
	
public:

	void castSpell(){cout<<"Spell Cast"<<endl;};
};

#endif // SPELLCASTER_H

Please help, been struggling for hours

3
Contributors
9
Replies
10
Views
6 Years
Discussion Span
Last Post by Fbody
0

>>"Board.C: In member function ‘void Board::input(bool)’:

Are you sure that is the correct filename? *.C programs are usually compiled as C, not C++.

0

We've been using .C files the whole year at varsity. It worked before

0

what compiler are you using? AFAIK all c++ files are named either *.cpp or *.cc, depending on the compiler. g++ on *nix normally use *.cc.

0

Im using g++

Edited by Mbot: n/a

0

I used vc++ 2010 express on Windows and did not have a problem compiling your header files. I also compiled it ok with Code::Blocks which uses MinGW (Windows port of g++)

Edited by Ancient Dragon: n/a

0

I cant understand, Im using linux g++ compiler.

0

I just compiled them on Ubuntu with Code::Blocks and did not get that error either. Maybe the problem is either in your makefile or something else that you did not post.

0

Ill rewrite my makefile and see if that works

0

what compiler are you using? AFAIK all c++ files are named either *.cpp or *.cc, depending on the compiler. g++ on *nix normally use *.cc.

This is the third thread I have seen on this same assignment, at least.
"';' expected before class"
"Initializing specific objects"

The OPs classmates are having similar issues. They all call their files "*.c" as well.

@OP:
I don't think calling that function as a member of the object is possible. You could potentially call it from inside the class if you resolve the name's scope properly. Since the error mentions that the error occurs inside Board::Input() I suspect that you haven't implemented it correctly. Please post the implementation of the function.

Edited by Fbody: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.