Hi, @Renjie Zhang
Provide a function declaration in the header(.h) file and provide a definition of the function in the associated .cpp file.
declaration :
//Sum.h
int sum(int a, int b);
definition :
//Sum.cpp
#include"Sum.h"
int sum(int a, int b)
{
return a + b;
}
Use the function in ConsoleApplication.cpp
#include<iostream>
#include"Sum.h"// include the header file
int main()
{
int i = sum(10, 32);
int j = sum(i, 66);
std::cout << "The value of j is" << j << std::endl; // 108
}
Best regards,
Minxin Yu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.