"Error: class not defined"

Hello! I am trying to learn C++ but I've hit a bit of a brick wall:
http://i.imgur.com/xliNACa.png

I have no idea what is causing that error, I've tried everything I can think of. I am using GNU GCC with Code::Blocks on Linux.

main.cpp: http://pastebin.com/y3eDvgny
capybara.h: http://pastebin.com/VCPgfCLY
capybara.cpp: http://pastebin.com/b54xdG5L (error is in this file)

Last edited on
In capybara.h:
You are including <iostream>, but nothing in header requires it.
You are using string, but do not include <string> which is reqired. (Same for capybara.cpp)

And most importantly: never place using namespace in headers. It can silently break so much for any user of this header.
Line 11: you write `Cabybara' instead of `Capybara'

Next time, paste your error messages as text.
And bother yourself two seconds to check your post.
MiiniPaa:
Thanks! But, I have a few questions (please forgive me if they are silly, I am very new to C++):
What can using namespace mess up and why?
Since I had using namespace std; in capybara.h and capybara.cpp (whether or not it is good practice), why do I still need to #include <string> seperatly?

ne555:
Thanks for showing me that, I don't know how I didn't notice that. I guess I need to work on being more observant. About the mistakes in the OP, I made that post after being awake for 36 hours (partially due to staring at this code) so I am very sorry for any errors as it was copy/pasted from another forum that did not even reply at all (probably due to most people on that forum mainly programming in Java).
why do I still need to #include <string> seperatly?
Because you should include headers for anything you use. std::string is defined in <string> header. So if you not include it, your program is not guaranteed to work. It moght work for you but not for others, and even for you if you update your compiler, change some settings. using namespace has nothing to do with included definitions. It only dumps names from some namespace in global.

What can using namespace mess up and why?
http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice
http://stackoverflow.com/questions/2712076/how-to-use-an-iterator/2712125#2712125

Additionally:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <algorithm>
using namespace std;
void func1();
void func2();
int count;

int main()
{
    int i;
    for (i=0; i<10; i++) {
        count = i * 2;
        func1();
    }
}
void func1()
{
    func2();
    std::cout << "count: " << count;
    std::cout << '\n';
}
void func2()
{
    int count;
    for(count=0; count<3; count++) std::cout<< '.';
}
Try to compile it. It will give you an error. Remove using namespace std and it will work fine. Now imagine if you have code like that and you will include header with using namespace in it without knowing.
Last edited on
Topic archived. No new replies allowed.