when you write code in the main function if you put functions in the file all you do is nameoffunction(); to call it. now my question is this lets say you have a menu in a class. call it bank. in the main to call that function . ive tried calling it the same way but that wont work because function isnt in main file. i thought that if you declared a class object .. bank account; then account.nameofFunction(); it would call it but it says there is a link error .. how do i call a function holding a menu from my main is actually my question ive gotten myself lost
buckeyemike
0
Newbie Poster
Recommended Answers
Jump to PostYou lost me but.. If the class is declared in a different file, you must include that header file in your main by doing #include "HeaderFile.hpp" or whatever extension you saved it as.
If it is declared in main like so then you just create an instance of that class …
Jump to PostIn C++, every cpp file is compiled separately, and then linked together. When the functions appear in the same cpp file as the
main()
function, then it is compiled together and doesn't need linking. When the functions appear in a different cpp file, then all the compiled cpp files …
All 5 Replies
triumphost
120
Posting Whiz
tinstaafl
1,176
Posting Maven
buckeyemike
0
Newbie Poster
ravenous
266
Posting Pro in Training
mike_2000_17
2,669
21st Century Viking
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.