Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function declaration/definition

Status
Not open for further replies.

paramecula

Technical User
Nov 23, 2004
3
0
0
GB
This is my first VC++ app, so apologies for the stupid question.

In my app, I want to call various user-defined functions. When I try to compile, I'm getting a 'undeclared identifier' error for each function call. From what I've read, I have to declare the function before I use it, but where do I do this and how ?

The VC++ books I have don't address this and the C++ ones say to declare it before int main() function, which doesn't seem to apply to VC++.

Any help appreciated
 
easy:

void MyFunction(int nParam1);

int main(int argc, char* argv[])
{
MyFunction(1);
}

void MyFunction(int nParam1)
{
// Do something
}

Hope that helps!

Skute

"There are 10 types of people in this World, those that understand binary, and those that don't!"
 
Thanks for the quick reply.

My app is dailog-based and I pasted your code into the Dlg.cpp file and it compiles OK. But when I replace your 'do something' with what I want to do (m_webbrowser.Navigate("url",...)), I get an error telling me that m_webbrowser is an undeclared identifier.

I've already used this variable successfully on a button on the app using a BN_CLICKED message and it opened the website I typed into the url parameter. Why doesn't it like m_webbrowser now ? Do I have to do something with the browser class/.cpp/.h in order for it to 'see' the new function I'm using it in ?

Thanks in advance.
 
Make sure the function you are trying to call m_webbrowser.Navigate() from is declared and defined as a member of the class to which m_webbrowser belongs. Sometimes I forget to add the CMyClass:: before the function name in the definition, which causes this kind of problem.
 
Define all your classes and functions in separate header files and put their implementation in .cpp files. Include the header files wherever you plan on using those classes/functions.
Also, make sure to put the proper #ifndef statements in the header files so you don't include it more than once.
Example:
Code:
// Header for CObject class.
#ifndef COBJECT_HEADER
#define COBJECT_HEADER

class CObject
{
public:
    CObject();
    virtual ~CObject();
};

#endif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top