i haave a method that is supposed to return a pointer. there are two classes team and player. the method is in team and returns a pointer to a player. i have something writtend but i keep getting definition or declaration errors. any ideas as to how to properly declare such a method?
Comments
:
:
Just at a guess, have you declared the player class after the team class? This will create a declaration problem in team unless you use a forward declaration to remedy the problem. Try to be a bit more specific and/or show some code, it'll help us help you. I hope this helps.
findPlayer is defined in the header as a public method simply as seen above.
the code is something like
team::player* findPlayer(int playNumb){
//currentPlayer pointer assigned to head
//while loop to compare currPlayer number to passed number
//if-else statement to return pointer or continue down linked list
//final return as NULL if not found
}
Im pretty sure it is something about how i declare it, Im just dont know what the right declaration is.
[CODE]
#include
#include
using namespace std;
class F_Class{
private:
int Stuff;
public:
F_Class(){
Stuff = 0;
}
~F_Class(){// Do Nothing.
}
};
class S_Class{
private:
F_Class * Fred;
public:
S_Class(){
Fred = NULL;
}
S_Class(F_Class * One){
Fred = One;
}
~S_Class(){ // Do Nothing.
}
F_Class * Get_Data_Ptr(void);
};
F_Class * S_Class::Get_Data_Ptr(void)
{
return Fred;
}
int main(void)
{
F_Class First;
S_Class Second(&First);
cout << Second.Get_Data_Ptr() << endl;
system("PAUSE");
return 0;
}
[/CODE]
I hope this will help you out rather than confuse you more.
team::player* findPlayer(int playNumb){
}
then I will suggest do this:
player* team::findPlayer(int playNumb){
}
I think u've already got better concept from Griz803's example.
bye, hope it helps
--------------->ASH
: Well, you're still not getting enough code through my thick skull as to what may be your problem. Below is an example of two classes with one that has a method to return a pointer. It is probably a good deal simpler than what you need, but maybe some experimentation with it by you can shine a light for you.
: [CODE]
: #include
: #include
:
: using namespace std;
:
: class F_Class{
: private:
: int Stuff;
:
: public:
: F_Class(){
: Stuff = 0;
: }
: ~F_Class(){// Do Nothing.
: }
: };
:
: class S_Class{
: private:
: F_Class * Fred;
:
: public:
: S_Class(){
: Fred = NULL;
: }
: S_Class(F_Class * One){
: Fred = One;
: }
: ~S_Class(){ // Do Nothing.
: }
: F_Class * Get_Data_Ptr(void);
: };
:
: F_Class * S_Class::Get_Data_Ptr(void)
: {
: return Fred;
: }
:
: int main(void)
: {
: F_Class First;
: S_Class Second(&First);
: cout << Second.Get_Data_Ptr() << endl;
:
: system("PAUSE");
: return 0;
: }
: [/CODE]
: I hope this will help you out rather than confuse you more.
: