can please me know how can avoid error.. in advance.
file name: point.hh
#ifndef point_h #define point_h class point{ private: int x; int y; public: point(); }; #endif file name:point.cc
#include "point.hh" #include <iostream> using namespace std; point::point() { x=0; y=0; cout<<"x="<<x; cout<<"y="<<y; } file name: main.cc
#include"point.cc" int main() { point p; // calls our default constructor }
you must include header file, not source file, in main.cc file use point class.
that is, replace:
#include"point.cc" by:
#include"point.hh" the rationale behind function definition, unless marked inline, must respect odr ("one definition rule"). including source file in other source file, end having 2 (identical) definitions of point::point() function in 2 different translation units.
when linking process takes place, sees 2 definitions , complains: error get.
Comments
Post a Comment