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

>>"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++.

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

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.

Im using g++

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++)

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

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.

Ill rewrite my makefile and see if that works

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.

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.