By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,619 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

main function not found

P: n/a
Hello All,
From a book where I have learned C++ it says that each application must

have at least one
function which is the main() function. Now I have the source code of a
C++ program from someone else. But whatever I am doing to search for
the main function, I can not find it. There is a very short description
of the program in a Readme file where it says that the main program is
located in a class "MytoolApp". I've had a look in this class which
seems to be derived from the "CWinApp" class. What is a "CWinApp" class
? I could not find any function called main() in this "MytoolApp"
class. Can anyone explain this to me ?
Many thanks in advance.
Robert

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

wo*********@yahoo.com wrote:
Hello All,
From a book where I have learned C++ it says that each application
must have at least one
function which is the main() function. Now I have the source code of a C++ program from someone else. But whatever I am doing to search for
the main function, I can not find it. There is a very short description of the program in a Readme file where it says that the main program is located in a class "MytoolApp". I've had a look in this class which
seems to be derived from the "CWinApp" class. What is a "CWinApp" class ? I could not find any function called main() in this "MytoolApp"
class. Can anyone explain this to me ?
Many thanks in advance.
Robert


This is an MFC application, there is no 'main'. There is
'InitInstance', but no 'main'. Try google for "cwinapp mfc" and you
should find some information.

Hope this helps,
-shez-

Jul 23 '05 #2

P: n/a

Check out below.

wo*********@yahoo.com wrote:
Hello All,
From a book where I have learned C++ it says that each application
must have at least one
function which is the main() function.
Correct.
Now I have the source code of a
C++ program from someone else. But whatever I am doing to search for
the main function, I can not find it. There is a very short description of the program in a Readme file where it says that the main program is located in a class "MytoolApp". I've had a look in this class which
seems to be derived from the "CWinApp" class. What is a "CWinApp" class ? I could not find any function called main() in this "MytoolApp"
class. Can anyone explain this to me ?
Inorder to implement complete OOPS in C++, we can declare and implement
a class, which when initialized as global object, calls the constructor
of that particular class. This does n't need a main function. This
method is utilized in MFC(Microsoft Foundation Classes). So,
constructor of MyToolApp is the start of the program. But, MFC class
CWinApp calls the InitInstance() method in that particular class, so
InitInstance is the main method of the program.
Many thanks in advance.
Robert


Jul 23 '05 #3

P: n/a
On 6 Feb 2005 04:41:44 -0800, "wo*********@yahoo.com"
<wo*********@yahoo.com> wrote in comp.lang.c++:
Hello All,
From a book where I have learned C++ it says that each application must

have at least one
function which is the main() function. Now I have the source code of a
C++ program from someone else. But whatever I am doing to search for
the main function, I can not find it. There is a very short description
of the program in a Readme file where it says that the main program is
located in a class "MytoolApp". I've had a look in this class which
seems to be derived from the "CWinApp" class. What is a "CWinApp" class
? I could not find any function called main() in this "MytoolApp"
class. Can anyone explain this to me ?
Many thanks in advance.
Robert


The MFC (Microsoft Foundation Classes) which are by the way off-topic
here, bury the main() function internally.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 23 '05 #4

P: n/a
* wo*********@yahoo.com:
From a book where I have learned C++ it says that each application must

have at least one function which is the main() function. Now I have the
source code of a C++ program from someone else. But whatever I am doing
to search for the main function, I can not find it. There is a very short
description of the program in a Readme file where it says that the main
program is located in a class "MytoolApp". I've had a look in this class
which seems to be derived from the "CWinApp" class. What is a "CWinApp" class
? I could not find any function called main() in this "MytoolApp" class.
Can anyone explain this to me ?


There are two ways a C++ program can apparently or actually be without a
'main' function, and both probably apply in your case.

First, that you're using an application framework that has a 'main'
function that in turn calls a function (e.g. a member function) in
your code. If you don't have the application framework source code
you'll not see 'main' anywhere. Even though it might be there.

Second, the standard differentiates between _hosted_ and _freestanding_
implementations of the language. Freestanding is meant for e.g. embedded
systems programming, where it's impractical to provide all the features
of the standard library, or even a 'main' function. For purposes of formalism
most Windows C++ implementations must be regarded as freestanding, because
they allow and to a certain practical extent require other startup functions
than 'main', e.g. 'wmain', 'WinMain' and 'wWinMain' (a Microsoft convention);
and these names might be hidden in macros, e.g. 'tmain' (a macro).

What you have seems to be an MFC Windows GUI application, as Jack Klein
pointed out, and if so then both apply: first, you're using an application
framework that provides the startup function, and second, the C++
implementation is a freestanding one where most probably the startup function
is not 'main' but (non-standard, implementation-defined) 'WinMain'.

Hope this helps,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.