1 Replies - 191 Views - Last Post: 11 September 2012 - 08:35 PM Rate Topic: -----

#1 wc1027  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 71
  • Joined: 29-March 11

calling a cpp file from another cpp file error

Posted 11 September 2012 - 06:59 PM

I have a cpp file that does one thing. and then have my main cpp file that i want to call the the other.
ie. say main.cpp calls calc.cpp. If that possible? how would you do it because i though you would #inlclude "calc.cpp" in main.cpp but it keeps saying

[Error] redefinition of 'int main()'.

If its not good pratice than I guess i could make a function in main to do it. but curious if it can be done.

Is This A Good Question/Topic? 0
  • +

Replies To: calling a cpp file from another cpp file error

#2 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 980
  • View blog
  • Posts: 3,401
  • Joined: 19-February 09

Re: calling a cpp file from another cpp file error

Posted 11 September 2012 - 08:35 PM

The main function is where the program starts, so it cannot start in two places.

You could rename the main in one file and call it in another.

Although you can #include "calc.cpp" in main.cpp and it may work (up to a point), it is usual to add the other cpp file to your project.

Header file
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1