Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function

Status
Not open for further replies.

mayu03

Programmer
Oct 3, 2003
91
US
I have a class cat and i am trying to pass an array of cat obiject to a function as well as valid components of the array.
void show(Cat cats[], int i)
What is incorrect in my line?
 
so far everything is correct.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
So why i am getting this error?
error C2065: 'Cat' : undeclared identifier
 
'Cat' : undeclared identifier
means in your code Cat is not declared. Declare it first and everything will be fine.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
I have a declaraliton in my main function:
Here how my code looks:

void show(Cat cats[], int i)
{.........}

void main
{
int new_size=SIZE;
Cat *cats=new Cat[new_size];.......
}
 
my class not in a sepate file header. everything in one .cpp
 
Is the order of declaration that cat is before the funtion? If not, try forward declarations

EX: .cpp file

// beginning of file
class Cat;
class Dog;

// functions

// end of file

Matt

 
Maybe it's defined after being used?
In that case you should forward declare it.

Greetings,
Rick
 
Yeah, Zyrenthian obviously types faster than I do....

Greetings,
Rick
 
I try this way:
...
int new_size=SIZE;
Cat *cats=new Cat[new_size];
.......
void show(Cat cats[], int i)
{.........}
void main
{.... }
and this way
.......
void show(Cat cats[], int i)
{.........}
int new_size=SIZE;
Cat *cats=new Cat[new_size];
void main
{.... }

Still not working the same error.

 
Yes.. but where do you declare the type (class struct typdef etc) for "Cats" ?

Matt
 
yes, but WHERE?? --> BEFORE you're using it or AFTER you're using it??

Greetings,
Rick
 
put this at the first line in your code:
struct Cat;

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
I found my error.I was placing function before class and my compiler can't associate this function with class. Thank you all for the help. :)
 
Just musing,

the postings by LazyMe & Zyrenthian by themselves have been good examples of 'forward declarations'

:)

In the sweat of thy brow shall you eat your bread.
-Bible

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top