What changes you can do in the header files to avoid the redefinition that compiler will give when both the header files

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

What changes you can do in the header files to avoid the redefinition that compiler will give when both the header files

Post by answerhappygod »

Content of h1.h
------------------------------------------------
h1.h
#include <iostream>
using namespace std;
int func(int a){
cout<<"Multiplied by 2";
return 2*a;
}
------------------------------------------------
 
Content of h2.h
------------------------------------------------
h2.h
#include <iostream>
using namespace std;
int func(int a){
cout<<"divided by 2";
return a/2;
}
------------------------------------------------
a) Cannot be handled because C++ does not allow this
b) Declare both the function inside different namespaces
c) Include one header files where they are needed so that no clashes occur
d) Make the header files name same
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!

This topic has 1 reply

You must be a registered member and logged in to view the replies in this topic.


Register Login
 
Post Reply