![]() |
| | #1 | |
| Registered User Join Date: May 2008
Posts: 20
| I'm having some trouble now with calling functions. Even tough I have a header file being called in the correspondent .cpp file it gives me the consequent error (in Visual C++ 2008 Expression Edition): Quote:
AirLine.h Code: #pragma once
#include "Form1.h"
#include "Person.h"
#include <cstdlib>
#include <iostream>
#include <string>
#include <map>
using namespace std;
class AirLine
{
public:
//int main(array<System::String ^>);
void menu(void);
void loginUser (void);
void registerUser(void);
};
Code: // AirLine.cpp : main project file.
#include "stdafx.h"
#include "AirLine.h"
static Person person;
//[STAThreadAttribute]
void registerUser()
{
(...)
registerUser();
(...)
}
void loginUser ()
{
(...)
menu(); // the error above goes here
(...)
}
void menu()
{
(...)
switch(option)
{
case 0: exit(1);
case 1: loginUser(); break;
case 2: registerUser(); break;
}
}
}
int main(array<System::String ^> ^args)
{
menu();
return 0;
}
Any guesses? :\ Thanks in advance, Joăo | |
| blacknail is offline | |
| | #2 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| We kind of hate that... If we're not seeing the real code we can't find the bug. If your code is truly tremendous, post it as an attachment instead of in-line, but in any case please always submit the entire code.
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
| | #3 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| So there's menu() and there's AirLine::menu(). The prototype for the second (in the class) won't help you find the first. (The same thing would be true for registerUser and loginUser; you're declaring the second, and defining the first.) |
| tabstop is offline | |
| | #4 |
| Registered User Join Date: May 2008
Posts: 20
| Solved my problem, I decided to separate the AirPlane class from the class with the main() function. I shouldn't have mixed up the main project file with functions of another class, but since I was not having problems I kept going... Thanks again for all the support! [[]] João |
| blacknail is offline | |
| | #5 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| As I see, loginUser tries to call menu that is... defined later. Oops. The compiler doesn't know of the existence of the menu function yet. So how do you solve that? Easy. You create a declaration of the function (all of the functions), stuff them into a header and include it in the .cpp file, as well as any other file that's going to use the functions inside that .cpp file.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #6 |
| Registered User Join Date: Sep 2009
Posts: 1
| Hi, i am currently facing the same problem...do you mind giving a few examples on how to declare the functions inside the header? |
| splicer is offline | |
| | #7 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| Code: void menu(); // Declaration. Goes into header.
void menu() // Definition. Goes into .cpp file.
{
}
class MyClass // Class definition. Goes into header.
{
public:
void menu();
};
void MyClass::menu() // Class implementation. Goes into source file (.cpp file).
{
}
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
![]() |
| Tags |
| c3861, error, found, identifier |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| An error is driving me nuts! | ulillillia | C Programming | 5 | 04-04-2009 09:15 PM |
| Problem with Mouse Over Menu!!! HELP!!! | SweeLeen | C++ Programming | 3 | 02-09-2006 02:10 AM |
| Best "Menu" method? | SSJMetroid | Game Programming | 11 | 12-08-2005 12:05 AM |
| Why wont my function exit correctly? | LightsOut06 | C Programming | 2 | 10-09-2005 09:23 PM |
| Going out of scope | nickname_changed | C++ Programming | 9 | 10-12-2003 06:27 PM |