|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
C and C++
I'm a new C leaner and i'm using DEc c++ as a compiler. Sometimes i got confused between C and C++ and my textbook doest mention that problem.
Can you guys tell me about defineing one function inside another function. E.g ..... int ab(void) { int abc(void); int abc(void) { ; } ... If i compile it with C, the compiler gives a warning but still runs the prob. But with C++, it does not. Thank you. |
|
#2
|
||||
|
||||
|
I'm not sure about C, but I know that in C++ you cannot define a function within another function. It specifically states this as an error when you compile the program. What is the warning that you get when you compile it in C?
__________________
Jason Doucette / Xona.com™ - Programming Windows Errata Addendum "Discussion is an exchange of knowledge; argument is an exchange of ignorance." |
|
#3
|
||||
|
||||
|
In the future please use an appropriate subject title. See the "How to Post" sticky thread at the top of this forum for more information.
|
|
#4
|
|||
|
|||
|
I'm sorry. Ididnt mean making it sticky.
|
|
#5
|
||||
|
||||
|
It's not a problem, this was just a gentle nudge not to do so again. The thread I pointed you to will give you some good guidelines as to how to post an appropriate subject title.
You can also follow the links in my signature for more information. Also, just curious, but why would you want to declare/define one function inside of another one? |
|
#6
|
|||
|
|||
|
I just got that idea when studying the scope of functions and variables.
|
|
#7
|
||||
|
||||
|
Typically it isn't a really good idea. Hence the reason why you get errors/warnings from it.
|
|
#8
|
|||
|
|||
|
Neither language, C nor C++, permits functions within functions.
|
|
#9
|
||||
|
||||
|
Quote:
Yeah, thats what I thought. As it was brought up before, where would be the purpose in that? You can either delare function prototypes before he main func, or simply write the entire function above and not declare anything. |
|
#10
|
|||
|
|||
|
So how can I limit only one function can call one specific function by not defining it within the other.
|
|
#11
|
||||
|
||||
|
I'm not sure I follow. But if I do, you can define it above, and then call it only from the function that you want to use it.
|
|
#12
|
|||
|
|||
|
Quote:
Perhaps you can describe more clearly what it is you're trying to do - just what, rather than how. I can think of ways to limit access to a function but I'm not sure that it'd achieve what you're after without understanding your needs better. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Defining a function within a function(use to be: C and C++) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|