-
using perameters in VC++
Using AppWizzard (exe)
Dialog Based
So is it possible to actually use perameters in member functions in VisualC++
I tried this and it says some strange error like I cant overload this function; when I wasnt overloading it, I was merely calling it from a single function inside a button.
Code looked something like this:
Code:
void OnButton1()
{
int integer=1;
function(integer);
}
void function(int number)
{
if(number==1)
number=2;
}
So is there a way of using perameters without getting errors while using VisualC++
-
It would help if you posted a more complete example. But yes, it is of course possible to use parameters in member functions:
Code:
#include <iostream>
class Foo
{
public:
void Bar(int num) { std::cout<<"Num is: "<<num<<std::endl; }
};
int main()
{
Foo obj;
obj.Bar(5);
}
Don't know if that helps, but I can't do much better without more details.
-
A member function is defined as a function declared within a class definition. I'm myself a newcommer to C++, but please don't take it wrong when I advise you to be careful in the way you use C++ terminology.
The language offers so much functionality that it is common for its nomenclature to be confusing (I feel this everytime when asking for help). And some of the terms used are lexically so close to each other that sometimes we ask something and get an answer to something else in return. Simply because we didn't use the correct terminology when asking our question.
Functions do have parameters. A function would not exist without those. A function declaration is usually composed of the following elements:
return_type function_name (parameter_list);
Even a function that was built to not accept any parameters (you can do that), is usually defined as:
return_type function_name (void);
As such...
Code:
double divide (long a, long b);
Is defined as a function called divide that returns a double-precision floating-point and accepts two long integer parameters.
A function parameter list can be much, much, more complex than just this. Parameters can be of any built-in type (long, int, char, ...), can be of any user-defined type (classes, enumerators, structs,...), can be constants, can be pointers, can be references, can be arrays, ...
As you develop your knowledge of C++ you will learn to use these and also look at functions as one of the most powerful features of C++ specifically, and that of any programming language that uses them.
By the way, member functions being themselves normal functions (only being declared insides a class definition) accept parameters too :)