using perameters in VC++

This is a discussion on using perameters in VC++ within the C++ Programming forums, part of the General Programming Boards category; Using AppWizzard (exe) Dialog Based So is it possible to actually use perameters in member functions in VisualC++ I tried ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    5

    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++

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    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.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,581
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. built-in variables for VC?
    By George2 in forum Tech Board
    Replies: 1
    Last Post: 08-20-2006, 06:02 AM
  2. makefile exported by vc 6.0 doesn't work
    By wow in forum Windows Programming
    Replies: 7
    Last Post: 03-24-2006, 04:20 PM
  3. Can't compile this with VC 6.0
    By uriel2013 in forum C++ Programming
    Replies: 4
    Last Post: 05-31-2003, 08:43 PM
  4. VC 7.0 and templates
    By Mongush in forum C++ Programming
    Replies: 12
    Last Post: 03-11-2003, 10:32 AM
  5. Why VC?
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 04-15-2002, 06:24 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21