I was trying to access the classes from different files. So , like a normal procedure, I made a new class, added the required codes and added the necessary preprocessor. But when i try to run the program, it says that my class has not been declared. I am not able to understand the cause. I am providing you the codes. Please help me out!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//the main file.cpp....................
#include <iostream>
#include "sally.h"
usingnamespace std;
int main()
{
sally a(23);
sally b(87);
sally c;
c=a+b; // it gonna run operator+
cout<<c.num;
return 0;
}
Did you make sure you added the files to your project file? This is different than the preprocessor directives. I know that for at least Code::Blocks, you have to both use #include and "add" files to the project.
Also there are four mistakes with your sally.cpp file.
1) The default constructor, sally(), makes use of a non-existent "a" variable.
2) There is no definition for the sally(int) constructor.
3) You misspelled iostream
4) You are using a deprecated iostream.h header. Just use iostream as you did in your main.cpp file.