Superclass and subclasses

Good day cplusplus.com and fellow members!.
I was wondering about the coding here.

1
2
3
4
5
6
7
8
9
10
11
12
13
//main.cpp
#include <iostream>
#include <string>
#include "class.h"
using namespace std;

int main() {
	string types = "normal", ages = "18";
	Animal anim;
	anim.doSomething(types,ages);
	cin.get();
	return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
//class.h
class Animal
{
public:
	virtual void doSomething(string type, string age);
};

class Cat : public Animal
{
public:
	virtual void doSomething(string weight, string height);
};


1
2
3
4
5
6
7
8
9
10
11
//class.cpp
#include <iostream>
#include <string>
#include "class.h"

using namespace std;

void Cat::doSomething(string weight, string height)
{
	cout<<"Cat "<<weight<<height<<endl;
}


There is a couple of error shown for the codes above.
1
2
3
4
5
6
7
8
1>c:\users\brandon-i5\documents\visual studio 2008\projects\ahnihmal\ahnihmal\class.h(4) : error C2061: syntax error : identifier 'string'
1>c:\users\brandon-i5\documents\visual studio 2008\projects\ahnihmal\ahnihmal\class.h(10) : error C2061: syntax error : identifier 'string'
1>c:\users\brandon-i5\documents\visual studio 2008\projects\ahnihmal\ahnihmal\main.cpp(9) : error C2660: 'Animal::doSomething' : function does not take 2 arguments
1>class.cpp
1>c:\users\brandon-i5\documents\visual studio 2008\projects\ahnihmal\ahnihmal\class.h(4) : error C2061: syntax error : identifier 'string'
1>c:\users\brandon-i5\documents\visual studio 2008\projects\ahnihmal\ahnihmal\class.h(10) : error C2061: syntax error : identifier 'string'
1>c:\users\brandon-i5\documents\visual studio 2008\projects\ahnihmal\ahnihmal\class.cpp(8) : error C2511: 'void Cat::doSomething(std::string,std::string)' : overloaded member function not found in 'Cat'
1>        c:\users\brandon-i5\documents\visual studio 2008\projects\ahnihmal\ahnihmal\class.h(7) : see declaration of 'Cat'


Is there a way to fix this thing though?
Because i don't really understand much about SubClass and SuperClass because i tried to do something like that.I was taught by the lecturer about the .h and the .cpp
But the lecturer now wanted us to do a program using inheritance with SuperClass and SubClass.
I was wondering, how does the .h and .cpp actually connects to each other? The lecturer requires us to have at least 3x.cpp and 3x.h

Thanks alot fellow friends i hope you would help out with this problem and matter
Cheers!

Regards,
error0024
Remove #include <string> from class.cpp and put it in class.h, also, either put std::string in replace for string in the .h file or also use the using namespace std;

As a side note, passing the strings by value is not the best way to do this. By passing by value, the string cannot be updated as well as a copy is made. Well, we don't want it to be updated, but we definitely don't need a copy of it so pass it by const reference.
@clanmjc
Thanks for your advice on this.
I have removed the #include <string> from the class.cpp and it seems to be showing another problem.

But i will try to discover more about this.
If you look at the first error you have posted...
1>c:\users\brandon-i5\documents\visual studio 2008\projects\ahnihmal\ahnihmal\class.h(4) : error C2061: syntax error : identifier 'string'

It is reporting this error in class.h, string is an unknown identifier in this scope, 1 because you have not included <string> in the header, and two because it is part of the std namespace.
Topic archived. No new replies allowed.