1) Read compilers clarifications more carefully: it’s trying to help you.
In this case, it says what you write in your header file doesn’t match what you write in your source file, i.e. in the header file:
void numbers();
that's a function which doesn’t accept parameters and returns nothing
In the source file:
void Addition::numbers(int x, int y)
that's a function which accepts
two parameters and returns nothing.
2) In general, the idea is to include header files, not source files.
In your main.cpp:
#include"addition.cpp"
should be:
#include "addition.h"
Note: in general, you should
link against source file, not include them. If you don’t know about this topic, it means your developing environment is taking care of it for you.
3) The compiler will add the constructors you don't provide (again: in general). There're details to know (the so called rule of three/five/zero)
http://en.cppreference.com/w/cpp/language/rule_of_three
but, at this stage of your study, perhaps you just need to know you'd better not to declare the constructors you aren't going to define.
I think the constructor is just a way for main to call each object. |
I’d said to create or initialise each object.
4) If you don’t want to read the compilers reports, at least try to be more accurate when you copy & paste on the forum:
- paste the entire error description;
- post the code in a way that the error line pointed out by the compiler (“
declared at line 15 of”) matches the line in your code.
Here’s an example of working code:
Addition.h:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#ifndef CATSONAMRS_ADDITION_H
#define CATSONAMRS_ADDITION_H
class Addition
{
public:
int i;
int j;
void numbers(int x, int y);
};
#endif // CATSONAMRS_ADDITION_H
|
Addition.cpp:
1 2 3
|
#include "Addition.h"
void Addition::numbers(int x, int y) {}
|
main.cpp:
1 2 3 4 5 6 7 8 9 10 11 12
|
#include "Addition.h"
#include <iostream>
#include <limits>
int main()
{
Addition A1;
// system("Pause"); <-- http://www.cplusplus.com/forum/beginner/1988/
std::cout << "\nPress ENTER to continue...\n";
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
return 0;
}
|