Creating a Derived Class in C++ [duplicate] - c++

This question already has answers here:
Why have header files and .cpp files? [closed]
(9 answers)
Closed 8 years ago.
So im trying to make a Die class and a LoadedDie class where the Die class is the base and the LoadedDie class is derived. The only difference between the 2 classes is that the roll function in the LoadedDie has a 25% chance of getting the highest number, whereas the Die, has a 1/6 chance. This is my 1st time working with derived class and i seem to have quite a problem trying to complete this task. Can someone explain to me how it works and show me how i would do it with my classes (as im a visual learner and need examples). I know my base class (Die) works as i tested it out before moving to my LoadedDie.
Die.cpp
#include<iostream>
#include <cstdlib>
using namespace std;
class Die{
public:
Die();
Die(int numSide);
virtual int roll() const;
int rollTwoDice(Die d1, Die d2);
int side;
};
Die::Die():side(6){}
Die::Die(int numSide):side(numSide){}
int Die::roll() const{
return rand() % side + 1;
}
int Die::rollTwoDice(Die d1, Die d2){
return d1.roll()+d2.roll();
}
LoadedDie.cpp
#include<iostream>
#include <cstdlib>
#include "Die.cpp"
using namespace std;
class LoadedDie: public Die{
public:
LoadedDie();
LoadedDie(int numSide);
virtual int loadedroll() const;
};
LoadedDie::LoadedDie():side(6){}
LoadedDie::LoadedDie(int numSide):side(numSide){}
int LoadedDie::loadedroll() const{
if ((rand() % 2)+1) = 1){
return side;
}
return (rand() % (side-1)) + 1;
}
int LoadedDie::rollTwoDice(LoadedDie d1, LoadedDie d2){
return d1.roll()+d2.roll();
}
My DieTester.cpp (just a main class to test if the above classes work):
#include "LoadedDie.cpp"
#include<iostream>
#include<time.h>
#include <stdlib.h>
using namespace std;
int main(){
srand(time(NULL));
Die d(6);
LoadedDie dl(6);
cout << d.roll()<<endl;
cout<<"ld " << dl.roll()<<endl;
}
With the classes above, i get this error when i run my DieTester.cpp (if it helps):
In file included from DieTester.cpp:1:
LoadedDie.cpp: In constructor ‘LoadedDie::LoadedDie()’:
LoadedDie.cpp:13: error: class ‘LoadedDie’ does not have any field named ‘side’
LoadedDie.cpp: In constructor ‘LoadedDie::LoadedDie(int)’:
LoadedDie.cpp:15: error: class ‘LoadedDie’ does not have any field named ‘side’
LoadedDie.cpp: In member function ‘virtual int LoadedDie::loadedroll() const’:
LoadedDie.cpp:18: error: expected primary-expression before ‘=’ token
LoadedDie.cpp:18: error: expected ‘;’ before ‘)’ token
I believe that these errors are due to me not deriving the classes properly. Can someone explain to me how this is done?

While the commends about splitting the code into header and code files are all valid (do that NOW) they have nothing to do with the remaining errors and your questions. Lets go through them one by one:
LoadedDie.cpp: In constructor ‘LoadedDie::LoadedDie()’:
LoadedDie.cpp:13: error: class ‘LoadedDie’ does not have any field named ‘side’
LoadedDie indeed has no such member. It is a member of Die. You do not initialize the members of your base class in the derived class like that. Instead you have to call the constructor of the base class like this:
LoadedDie::LoadedDie() : Die() { }
LoadedDie.cpp: In constructor ‘LoadedDie::LoadedDie(int)’:
LoadedDie.cpp:15: error: class ‘LoadedDie’ does not have any field named ‘side’
Same problem again. Same solution:
LoadedDie::LoadedDie(int numSide) : Die(numSide) { }
Note that you can take advantage of default values for arguments and simply write one constructor instead of two:
class Die {
public:
Die(int numSide = 6);
....
}
if ((rand() % 2)+1) = 1){
LoadedDie.cpp: In member function ‘virtual int LoadedDie::loadedroll() const’:
LoadedDie.cpp:18: error: expected primary-expression before ‘=’ token
LoadedDie.cpp:18: error: expected ‘;’ before ‘)’ token
'=' is assignment while you ment equal '=='. You can't assign 1 to (rand() % 2)+1).

It's generally bad form to #include CPP files. But if you want to do it, get rid of the #include "Die.cpp" statement in main.cpp. It's already included in LoadedDie.cpp and so you are including it twice and defining it twice--hence the 'redefinition' error.

Related

Error request for member getName which is of non-class type 'char'

I'm trying to make a program involving files assign2.cpp, Player.h, Player.cpp, Team.h, Team.cpp which reads data from a txt file on player info (like hits, atBat, position, name and number) and displays it out into assign2.cpp. assign2.cpp is what contains int main() and is suppose to contain very little code because relies on the other files to do the work.
The error:
request for member getName which is of non-class type ‘char’...
Please help, I've been trying to find the issue and can never do so. The compilation failure :
In file included from Team.cpp:1:0:
Team.h:34:11: warning: extra tokens at end of #endif directive [enabled by default]
Team.cpp: In constructor ‘Team::Team()’:
Team.cpp:15:5: warning: unused variable ‘numPlayers’ [-Wunused-variable]
Team.cpp: In member function ‘void Team::sortByName()’:
Team.cpp:49:56: error: request for member ‘getName’ in ‘((Team*)this
-> Team::playerObject[(j + -1)]’, which is of non-class type ‘char’
Team.cpp:49:74: error: request for member ‘getName’ in ‘bucket’, which is of non-class type ‘int’
Team.cpp: In member function ‘void Team::print()’:
Team.cpp:63:18: error: request for member ‘print’ in ‘((Team*)this)- >Team::playerObject[i]’, which is of non-class type ‘char’
make: *** [Team.o] Error 1
Team.h
#ifndef TEAM_H
#define TEAM_H
#include "Player.h"
class Team
{
private:
char playerObject[40];
int numPlayers; // specifies the number of Player objects
// actually stored in the array
void readPlayerData();
void sortByName();
public:
Team();
Team(char*);
void print();
};
#endif / *Team.h* /
Team.cpp
#include "Team.h"
#include <cstring>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <cstdlib>
using namespace std;
Team::Team()
{
strcpy (playerObject,"");
int numPlayers = 0;
}
Team::Team(char* newPlayerObject)
{
strncpy(playerObject, newPlayerObject, 40);
readPlayerData();
}
void Team::readPlayerData()
{
ifstream inFile;
inFile.open("gamestats.txt");
if (!inFile){
cout << "Error, couldn't open file";
exit(1);
}
inFile.read((char*) this, sizeof(Team));
inFile.close();
}
void Team::sortByName()
{
int i, j;
int bucket;
for (i = 1; i < numPlayers; i++)
{
bucket = playerObject[i];
for (j = i; (j > 0) && (strcmp(playerObject[j-1].getName(), bucket.getName()) > 0); j--)
playerObject[j] = playerObject[j-1];
playerObject[j] = bucket;
}
}
Player.h (incase anyone needs it)
#ifndef PLAYER_H
#define PLAYER_H
class Player
{
// Data members and method prototypes for the Player class go here
private:
int number;
char name[26];
char position[3];
int hits;
int atBats;
double battingAverage;
public:
Player();
Player(int, char*, char*, int, int);
char* getName();
char* getPosition();
int getNumber();
int getHits();
int getAtBats();
double getBattingAverage();
void print();
void setAtBats(int);
void setHits(int);
};
#endif
I'm very stuck, Thanks in advance.
In the Team constructor on this line
playerObject = newPlayerObject;
you're trying to assign a value of type char* to a member of type char[40], which doesn't work, since they are two different types. In any case, you probably would need to copy the data from the input instead of just trying to hold the pointer internally. Something like
strncpy(playerObject, newPlayerObject, 40);
Generally, you will always be able to assign a char[N] to a char*, but not the other way around, but that's just because C++ will automatically convert the char[N] to a char*, they are still different types.
Your declaration is:
char playerObject[40];
And your constructor reads:
Team::Team(char* newPlayerObject)
{
playerObject = newPlayerObject;
The error message you referenced in the title of this question obviously comes from here, and it is self explanatory. An array and a pointer are two completely different, incompatible types, when it comes to this kind of an assignment.
What you need to do depends entirely on what you expect to happen, and what your specifications are.
A) You could be trying to initialize the array from the character pointer, in which case you'll probably want to use strcpy(). Of course, you have to make sure that the string, including the null byte terminator, does not exceed 40 bytes, otherwise this will be undefined behavior.
Incidently, this is what you did in your default constructor:
Team::Team()
{
strcpy (playerObject,"");
}
B) Or, your playerObject class member should, perhaps, be a char * instead, and should be either assigned, just like that, or perhaps strdup()ed. In which case your default constructor will probably need to do the same.
Whichever one is the right answer for you depends entirely on your requirements, that you will have to figure out yourself.

Request for member 'print' in 'y', which is of non-class type [duplicate]

This question already has answers here:
Why is there no call to the constructor? [duplicate]
(3 answers)
Closed 9 years ago.
I am going through Nicola Josuttis's OOP in C++ book and experimenting with his code using Code Blocks IDE. I am having difficulty understanding the compiler error message. I created a simple class interface (frac1.hpp), a class (frac1.cpp), and a test with main() - (ftest.cpp). The class accepts two integers which is printed out as a fraction. The class constructors set a default of 0 if called w/o any arguments, an integer value if called with 1 argument, or a fraction if called with 2 arguments. If one or two arguments are passed there is no compile error. But if no arguments are passed I expected the constructor to be initialized to 0, instead I get a compiler error about the print statement being of "non-class type". It is as though the object wasn't created. Any help or explanation of what I am doing wrong is greatly appreciated.
thank you kindly for your consideration.
Class description:
//frac1.cpp
#include "frac1.hpp"
#include <iostream>
#include <cstdlib>
//default constructor
Fraction::Fraction() : numer(0), denom(1) //initialize fraction to 0
{
//no further statements
}
Fraction::Fraction(int n) : numer(n), denom(1) //whole integer initialization
{
//no further statements
}
Fraction::Fraction(int n, int d) : numer(n), denom(d)
{
if (d==0) {
std::cerr << "error: denominator is 0" <<std::endl;
std::exit(EXIT_FAILURE);
}
}
void Fraction::print()
{
std::cout<<numer<<'/'<<denom<<std::endl;
}
Interface Description:
//frac1.hpp
#ifndef FRAC1_HPP_INCLUDED
#define FRAC1_HPP_INCLUDED
#include <istream>
#include <cstdlib>
namespace CPPDemo {
// Fraction Class
class Fraction {
private:
int numer, denom;
public:
Fraction();
Fraction(int);
Fraction(int,int);
void print();
};
}
#endif // FRAC1_HPP_INCLUDED
test file description:
//ftest.cpp
#include "frac1.hpp"
#include <iostream>
#include <cstdlib>
int main()
{
CPPDemo::Fraction y();
y.print(); //flagged as compiler error**
}
Message from Compiler:
C:\Users\User\Desktop\CPPDemo\FractionClassTest\ftest.cpp:9: error: request for member 'print' in 'y', which is of non-class type 'CPPDemo::Fraction()'
Change the test file to:
int main()
{
CPPDemo::Fraction y;
y.print(); //flagged as compiler error**
}
Without the () the compiler does not see y.prints as a function call. My knowledge of C++ syntax rules is not good enough to give a better explanation. sorry.
change
CPPDemo::Fraction y();
**y.print;
to
CPPDemo::Fraction y;
y.print();
Because the first declares a function, it does not declare the object you wanted.
And the print function needs brackets (I don't know what the ** were for)
You forgot the function braces ().
Try
y.print()
Oh damn, that got me again. You also need to fix the instanciation
CPPDemo::Fraction y;

c++ classes not talking [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
i am using gvim to do c++ for a class (since we are told we have to do it in linux, and the class is taught using c++). i have had java classes before, but this teacher isn't really telling us how to do things in c++ or linux since he states it's another class that just uses c++.
the problem i am having for my homework is that we have to create some classes and have them get info to each other, but i keep getting errors whenever i try to compile. (i can't seem to figure out how to get them to talk to each other and use functions/variables from one another.)
ex:
class a {
string user;
public: string user2;
public: vector<string> friendList;
public: void userName()
{
cout output
cin >> user;
}
public: void addFriend()
{
cout output
cin >> user2;
friendList.push_back(user2);
}
public: string getName()
{
return user;
}
};
(have tried this second class 2 ways and neither work)
way1--->
class b {
string message, username;
a User;
public: void postMessage()
{
cout ____
getline(cin, message);
username = User.getName();
}
};
or this way---->
class b: public a {
string message, username;
a User;
public: void postMessage()
{
cout ____
getline(cin, message);
username = User.getName();
}
};
(or had the function like this:)
public: void postMessage()
{
cout ____
getline(cin, message);
username = user2;
}
};
the classes don't seem to talk to each other either way, and i'm not sure how to get them to since these ways don't work and that's what was in the book/what i found on the internet so far.
so i guess my question is how can i get a to talk to b so b can use functions or variables from a? need to know so the classes can talk to eachother and also so i can get the main function to also call each class (each class is in a separate .cpp file btw).
EDIT:
(the classes are in different files)
i made a script for the terminal for the errors:
Script started on Sun 29 Sep 2013 02:27:42 PM CDT
]0;darksithis002#darkmist002-VirtualBox: ~/lab1darksithis002#darkmist002-VirtualBox:~/lab1$ g++ -c homepg.cpp
homepg.cpp:14:26: error: expected class-name before ‘,’ token
homepg.cpp:15:1: error: expected class-name before ‘{’ token
homepg.cpp:18:24: error: ‘user’ was not declared in this scope
homepg.cpp:18:24: error: ISO C++ forbids initialization of member ‘userName1’ [-fpermissive]
homepg.cpp:18:24: error: making ‘userName1’ static [-fpermissive]
homepg.cpp:18:24: error: invalid in-class initialization of static data member of non-integral type ‘std::string {aka std::basic_string<char>}’
homepg.cpp:19:19: error: ISO C++ forbids initialization of member ‘counter’ [-fpermissive]
homepg.cpp:19:19: error: making ‘counter’ static [-fpermissive]
homepg.cpp:19:19: error: ISO C++ forbids in-class initialization of non-const static member ‘counter’
homepg.cpp:20:30: error: ‘friendList’ was not declared in this scope
homepg.cpp:20:30: error: ISO C++ forbids initialization of member ‘friends’ [-fpermissive]
homepg.cpp:20:30: error: making ‘friends’ static [-fpermissive]
homepg.cpp:20:30: error: invalid in-class initialization of static data member of non-integral type ‘std::vector<std::basic_string<char> >’
homepg.cpp:22:5: error: ‘cout’ does not name a type
homepg.cpp:23:5: error: ‘cout’ does not name a type
homepg.cpp:24:5: error: ‘cout’ does not name a type
homepg.cpp:29:26: error: ISO C++ forbids declaration of ‘displayHome’ with no type [-fpermissive]
homepg.cpp: In member function ‘int homepg::displayHome()’:
homepg.cpp:31:12: error: ‘messageBuff’ was not declared in this scope
homepg.cpp:45:6: error: ‘nextbrac’ was not declared in this scope
homepg.cpp:53:18: error: ‘userName’ was not declared in this scope
homepg.cpp:64:28: error: ‘friends’ was not declared in this scope
homepg.cpp:85:6: error: ‘count’ was not declared in this scope
]0;darksithis002#darkmist002-VirtualBox: ~/lab1darksithis002#darkmist002-VirtualBox:~/lab1$ g++ -c messageBuffer.cpp
messageBuffer.cpp: In member function ‘void messageBuffer::postMessage()’:
messageBuffer.cpp:26:13: error: ‘user’ was not declared in this scope
messageBuffer.cpp: In member function ‘void messageBuffer::tweetMessage()’:
messageBuffer.cpp:45:17: error: ‘user’ was not declared in this scope
]0;darksithis002#darkmist002-VirtualBox: ~/lab1darksithis002#darkmist002-VirtualBox:~/lab1$ exit
exit
Script done on Sun 29 Sep 2013 02:29:16 PM CDT
as a test, i put 2 of my classes together, one that compiled fine on it's own, and one that needed a function/variable from the other class, and tried to compile, and they compiled fine as
class a {
*functions and variables for a* }
class b {
a A;
*functions for b* }
class b in this example just doesn't work if i have it in a separate file in the same directory trying to call a, it gives me the errors i got in the script i made.
EDIT2: i'm also getting an error in the test file if i put in a main function and have it call functions from class a and b. (i know this error is from not declaring the functions, but if i try to declare them in their class, they give me another error which is: type::functionname cannot be overloaded, but if i take out the declaration both a and b compile fine and b can use a's functions, so why is it that they can fine without function declartions but a main function can't? and where do i put the declarations for the functions if i can't have them in the classes since it says it can't overload them?)
First of all - you only need to write "public:" once and then everything after that is public (until you write "private:" or similar).
Second - your firt "class b" seems to be the correct one.
Third - are both classes written in the same file? Or in different files? If in differebt files - did you include the file for a in the file for b? Are they .h files or .cc files?
Edit: here's how it should be, lets say a single file for now:
one file, main.cc:
#include <string>
#include <vector>
#include <iostream>
using namespace std;
class a {
string user;
public:
string user2;
vector<string> friendList;
void userName()
{
cout <<"blah blah"<<endl;
cin >> user;
}
void addFriend()
{
cout <<"blah blah"<<endl;
cin >> user2;
friendList.push_back(user2);
}
string getName()
{
return user;
}
};
class b {
string message, username;
a User;
public:
void postMessage()
{
cout <<"blah blah"<<endl;
getline(cin, message);
username = User.getName();
}
};
int main(){
b test;
test.postMessage();
}
There are many issues with your classes obviously - but this should compile at least.
Here are some hints to get you moving!
Define one class per file, and wrap header files (*.h) in include guards.
File a.h
#ifndef A_H
#define A_H
#include <string>
#include <vector>
#include <iostream>
class a // This class needs a better name!
{
private: // Class members are private by default but it's best to be explicit
std::string user; // When using classes from the C++ Standard Library in a
// header file, specify the `std` namespace explicitly
public: // Everything below here is public
std::vector<std::string> friendList;
void userName()
{
std::cout << "User name: "; // Note the use of `std::` here otherwise you'll see
// ‘cout’ does not name a type
std::cin >> user;
}
void addFriend()
{
std::cout << "Add friend: ";
std::string user2;
std::cin >> user2;
friendList.push_back(user2);
}
std::string getName()
{
return user;
}
};
#endif
File b.h
#ifndef B_H
#define B_H
#include <string>
#include <iostream>
#include "a.h" // Tell the pre-processor to include the entire contents of `a.h`,
// so that the code below knows what `class a` is.
class b
{
private:
std::string message, username;
a User;
public:
void postMessage()
{
std::cout << "Post Message: ";
std::getline(std::cin, message);
username = User.getName();
}
};
#endif
File main.cpp
This is the only file you need to compile, since it includes b.h (and a.h within that).
#include "b.h"
int main()
{
b my_b;
my_b.postMessage();
}
In the code above, like "Way 1", class b contains an instance of class a.
If you wished class b to extend class a, like "Way 2", you would use something like this:
class b: public a
{
// [...]
public:
void postMessage()
{
std::cout << "Post Message: ";
std::getline(std::cin, message);
username = getName();
}
};
To compile
Either use the terminal:
g++ -I/usr/local/include -Wall -Wextra -pedantic main.cpp -o main
Or use a Vim Script like SingleCompile.

error: expected unqualified-id before ‘.’ token //(struct)

I need to make a program that gets a fraction from the user and then simplifies it.
I know how to do it and have done most of the code but I keep getting this error "error: expected unqualified-id before ‘.’ token".
I have declared a struct called ReducedForm which holds the simplified numerator and denominator, now what Im trying to do is send the simplified values to this struct.
Here is my code;
In Rational.h;
#ifndef RATIONAL_H
#define RATIONAL_H
using namespace std;
struct ReducedForm
{
int iSimplifiedNumerator;
int iSimplifiedDenominator;
};
//I have a class here for the other stuff in the program
#endif
In Rational.cpp;
#include <iostream>
#include "rational.h"
using namespace std;
void Rational :: SetToReducedForm(int iNumerator, int iDenominator)
{
int iGreatCommDivisor = 0;
iGreatCommDivisor = GCD(iNumerator, iDenominator);
//The next 2 lines is where i get the error
ReducedForm.iSimplifiedNumerator = iNumerator/iGreatCommDivisor;
ReducedForm.iSimplifiedDenominator = iDenominator/iGreatCommDivisor;
};
You are trying to access the struct statically with a . instead of ::, nor are its members static. Either instantiate ReducedForm:
ReducedForm rf;
rf.iSimplifiedNumerator = 5;
or change the members to static like this:
struct ReducedForm
{
static int iSimplifiedNumerator;
static int iSimplifiedDenominator;
};
In the latter case, you must access the members with :: instead of . I highly doubt however that the latter is what you are going for ;)
The struct's name is ReducedForm; you need to make an object (instance of the struct or class) and use that. Do this:
ReducedForm MyReducedForm;
MyReducedForm.iSimplifiedNumerator = iNumerator/iGreatCommDivisor;
MyReducedForm.iSimplifiedDenominator = iDenominator/iGreatCommDivisor;
ReducedForm is a type, so you cannot say
ReducedForm.iSimplifiedNumerator = iNumerator/iGreatCommDivisor;
You can only use the . operator on an instance:
ReducedForm rf;
rf.iSimplifiedNumerator = iNumerator/iGreatCommDivisor;

Exception Handling C++ error

#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
class div
{
int x,y;
public:
class dividebyzero
{
};
class noerror1
{
};
div(){};
div(int a,int b)
{
x=a;
y=b;
}
void error1()
{
if(y==0)
throw dividebyzero();
else
throw noerror1();
}
int divide()
{
return (x/y);
}
};
class naming
{
char name[32];
public:
class nullexception
{
};
class noerror2
{
};
naming(char a[32])
{
strcpy(name,a);
}
void error2()
{
if(strcmp(name,"")==0)
throw nullexception();
else
throw noerror2();
}
void print()
{
cout<<"Name-----"<<name<<endl;
}
};
int main()
{
div d(12,0);
try
{
d.error1();
}
catch(div::dividebyzero)
{
cout<<"\nDivision by Zero-------Not Possible\n";
}
catch(div::noerror1)
{
cout<<"\nResult="<<d.divide()<<endl;
}
naming s("Pankaj");
try
{
s.error2();
}
catch(naming::nullexception)
{
cout<<"\nNull Value in name\n";
}
catch(naming::noerror2)
{
s.print();
}
return 0;
}
On compiling this program I am getting following error
pllab55.cpp: In function ‘int main()’:
pllab55.cpp:61:6: error: expected ‘;’ before ‘d’
pllab55.cpp:64:3: error: ‘d’ was not declared in this scope
pllab55.cpp:72:22: error: ‘d’ was not declared in this scope
pllab55.cpp:74:20: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
Before declaring the class naming everything was running fine.It is after declaration of naming these error started to occur. I am new to C++. Please explain me in details. Thanks in advance.
There is already an std::div in the standard namespace and since you use a using namespace directive instead of declaration it imports all the symbols in std namespace to your current scope. So perhaps renaming the div class shall do the trick for you.
I tried renaming it and it does work indeed.
So either rename your class or wrap it in your own namespace so it does not conflict with std::div
Your class div shares the same name as std::div. When you do #using namespace std, the result is that each class in the std namespace is imported into your current scope, meaning that std::div is now essentially called div. If you see, that means you now have two classes called div in the same scope, your own and the std class.
By the way, you should avoid the using namespace syntax and rather use the full qualifier of the class (e.g. std::cout).
Your div class is conflicting with std::div so either rename yours or put put your div class in a different namespace.
namespace me {
struct div{};
}
me::div d;
I gave (a slight variant of) your code a try in gcc and I got the following error:
/usr/include/stdlib.h:780: error: too few arguments to function 'div_t div(int, int)'
You're trying to override a name from a standard library and experience the conflict of a class and a function having the same name, I'm afraid.
as a general rule of thumb, if you encounter such issues, try to reduce your code as much as possible. For instance, I reduced it down to
#include<stdlib.h>
class div {
public:
div (int a, int b) { }
};
int
main () {
div d (12, 0);
return 0;
}
which still shows your error (at least the first one - the others are followup errors).
This lets you also reduce possible assumptions about the reason for the error - as you see, your new class "naming" does not have to do anything with the error you see.
When I now additionally remove the include, the error does not show up anymore, which lets me suspect some naming clash with some symbol from stdlib.h. After renaming the class "div" to something else (like "CDiv"), it works.