Newbie problem: C2065 method is an unideclared identifier

Hey all,

I'm trying to work through a problem and I can't seem to figure it out. I can't seem to access a method from main that I have declared and defined in the same class, I'm new to c++ but know of Java and I think this is my downfall (if not

int main(void) {
...
vector<s *> vs;
vs.push_back( &c ); (c is a derived class of s)
...
drawer(vs);
}

void shapeutils::drawer(vector<s *> vec) {
for (vector<shape *>::iterator p = vec.begin(); p != vec.end(); p++) {
(*p)->draw();
}
}

I have no other errors except from...

c:\Documents and Settings\Earthwyrm\My Documents\Visual Studio Projects\cw2\shapeutils.cc(20): error C2065: 'drawer' : undeclared identifier

my .h file declares drawer like this...

void drawer(std::vector<shape *> vec);

I have found that if I don't call drawer, the main method works fine, as it 'draws' out my objects. When I introduce the three lines that you see in the main method I get the error. The error is not in me calling "(*p)->draw", as I have deleted this line and nothing changed. There is most probably some basic thing I am missing but I am at my wits end trying to figure it out.

Could anyone please help?
[1356 byte] By [noodle3811] at [2007-11-19 7:21:58]
# 1 Re: Newbie problem: C2065 method is an unideclared identifier
Did you include the header file that declares drawer??

#include "MyHeader.h"
Siddhartha at 2007-11-11 0:27:47 >
# 2 Re: Newbie problem: C2065 method is an unideclared identifier
Thanks for the quick reply, I only went to get a sandwich from downstairs :P

Yeah I've included the .h file, (sorry, forgot to mention that). Could it be anything to do with vector<s *> and push_back'ing the derived classes? I am especially unsure in this area of c++;
noodle3811 at 2007-11-11 0:28:47 >
# 3 Re: Newbie problem: C2065 method is an unideclared identifier
Why dont u post the entire code the way it is (doesn't seem big) and use the code tags?

I noticed that the definition of drawer and the declaration seem a bit different.

drawer the way it is defined belongs to class shapeutils. But, the one you are calling is global? I need code... !
Siddhartha at 2007-11-11 0:29:45 >
# 4 Re: Newbie problem: C2065 method is an unideclared identifier
actually it'll probly help if I post main, it's not that large due to all the commenting out :S

int main(void) {
circle c;
rectangle r;
triangle t;
c.draw(); r.draw(); t.draw(); cout.flush(); cerr << "OK-1\n";
//up to here works just fine, all information is printed to the dos prompt window
vector<s *> vs;
vs.push_back( &c ); vs.push_back( &r ); vs.push_back( &t );
drawer(vs);

return 0;
}
noodle3811 at 2007-11-11 0:30:49 >
# 5 Re: Newbie problem: C2065 method is an unideclared identifier
1. Why don't you use the CODE tags?2. Why not post the header and the definition of drawer too?
Siddhartha at 2007-11-11 0:31:43 >
# 6 Re: Newbie problem: C2065 method is an unideclared identifier
drawer is a member of shapeutils. You will need to instantiate a shapeutils object to use it.
GCDEF at 2007-11-11 0:32:53 >
# 7 Re: Newbie problem: C2065 method is an unideclared identifier
ok sure, I'm not sure about code tags though so I'll guess, here goes...
<CODE>

#include <vector>
#include <list>
#include <iostream>
#include "shape.h"
#include "circle.h"
#include "rectangle.h"
#include "triangle.h"
#include "shapeutils.h"
#include "complex.h"

using namespace std;

int main(void) {
circle c;
rectangle r;
triangle t;
c.draw(); r.draw(); t.draw(); cout.flush(); cerr << "OK-1\n";
vector<shape *> vs;
vs.push_back( &c ); vs.push_back( &r ); vs.push_back( &t );
drawer(vs);
return 0;
}

void shapeutils::drawer(vector<shape *> vec)
{
for (vector<shape *>::iterator p = vec.begin(); p != vec.end(); p++)
{
(*p)->draw();
}
}

//everything else is commented out
;
</CODE>

the header file:
<CODE>

#ifndef __SHAPEUTILS_H__
#define __SHAPEUTILS_H__

#include <vector>
#include <list>
#include <iostream>
#include "shape.h"
#include "rectangle.h"
#include "triangle.h"
#include "circle.h"
#include "complex.h"

//template<typename Container>;

class shapeutils
{
public:
void drawer(std::vector<shape *> vec);
};

#endif

</CODE>

worth noting that shape has derived classes that implement pure virtual methods, the only one I'm using at the moment is draw, which works when I call draw() from main, but not when called from
noodle3811 at 2007-11-11 0:33:54 >
# 8 Re: Newbie problem: C2065 method is an unideclared identifier
drawer belongs to a class. It is not a global method.
So, how can you call it as one inside main?

Secondly, can you not see the [CODE] tag in your editor?
It makes reading simpler. Look at other post, and see how Code tags work!
Siddhartha at 2007-11-11 0:34:46 >
# 9 Re: Newbie problem: C2065 method is an unideclared identifier
I am such a dumb***, I didn't really look the main method too much. Thanks a lot, once I again I live up to my nick lol. Sorry for the bother, and thankyou for the time.
noodle3811 at 2007-11-11 0:35:53 >
# 10 Re: Newbie problem: C2065 method is an unideclared identifier
I am such a dumb***, I didn't really look the main method too much. Thanks a lot, once I again I live up to my nick lol. Sorry for the bother, and thankyou for the time.You are welcome.
I am tempted to agree with you on the important points above! :D

Here is how code tag looks -
int nTestInteger = int ();

And yes, I do intend putting some people into a tailspin with that line of code! :D
Siddhartha at 2007-11-11 0:36:53 >
# 11 Re: Newbie problem: C2065 method is an unideclared identifier
yeah I got it working now, the problem was the main method my professor supplied, I should have seen it a mile off. I was reading up on container templates and the like.

#include <iostream>

int main(void)
{
std::cout << "thanks again";
return 0;
}

[CODE]
#include <iostream>

int main(void)
{
std::cout << "thanks again";
return 0;
}
[CODE]
noodle3811 at 2007-11-11 0:37:48 >
# 12 Re: Newbie problem: C2065 method is an unideclared identifier
yeah I got it working now, the problem was the main method my professor supplied, I should have seen it a mile off. I was reading up on container templates and the like.


#include <iostream>

int main(void)
{
std::cout << "thanks again";
return 0;
}
:D :D

All the best for your studies.

Ciao,
Sid! :thumb:
Siddhartha at 2007-11-11 0:38:57 >