The name pretty much says it all. How do you do it, specifically in header files?
The name pretty much says it all. How do you do it, specifically in header files?
use = after the parameter with the default value, this way if the parameter is missing when called this default value will be used, example:prints 3. hope this helpsCode:#include<iostream> int stuff(int a=3); int main() { std::cout<< stuff(); } int stuff(int a) { return a; }
Last edited by nadroj; 10-20-2006 at 02:25 PM.
Well, the problem that I'm having is in my header file... If I declare a function that takes an optional argument of NULL, it says NULL was not declared in this scope. What exactly does that mean?
I believe you want null not NULL
EDIT: Just tested it, hmm odd.
Last edited by Wraithan; 10-20-2006 at 03:08 PM.
do you have the proper code to reference the defined NULL value? try to include<iostream>. or instead of NULL just use 0 (zero) if need be. or post the relevant code if you can
NULL is defined in windef.h (which you get if you include windows.h) I agree though, 0 is what the MinGW implementation of Win32 API defines it as...
I don't have Win SDK from MS installed on this computer so I can't check what MS defines it as, but I will assume it is simular.Code:#ifndef NULL #ifdef __cplusplus #define NULL 0 #else #define NULL ((void*)0) #endif #endif
i get error if i try and reference NULL, however when iostream is included it works..since this is a popular header its not a bad idea to include this if it solves the problem.
windef??? NULL is defined in cstddef and cstdlib. That it works when including iostream is just coincidence.
Or just use the number 0. It works the same in C++.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Ahh, well it may be defined there too, I just know it was defined in the windows headers. I used Code::Blocks find declaration feature (I <3 it)
well it looks like theres afew CORRECT solutions here. he needs to include the most appropriate header which has a reference to the NULL definition.
Thanks! iostream, huh? A little odd.
The most appropriate if you need NULL is <cstddef>. <iostream> is inappropriate.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
why is inappropriate? it worked in my case, and ive read on university notes that it is defined in iostream.
im not trying to start an argue im trying to see why you say its better than what i have said. thanks
The easiest solution is to #include <cstddef> in the header file.Originally Posted by nadroj
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.