C function parameter default value issue

Updated on technology 2024-03-27
16 answers
  1. Anonymous users2024-02-07

    c Parameter defaults are not supported, and if you want to implement the same functionality, you can use the method of function overloading to simulate the implementation. Such as:

    void msgbox(string msg)

  2. Anonymous users2024-02-06

    1. There is no default value for the argument of c, and a(int a=1) cannot be compiled.

    2. To distinguish between two methods that are different, it is necessary to ensure that the method name is different or the method name is the same, but the method parameter declaration is different.

    Actually, your problem should be the problem of "method overload". If you have multiple methods with the same functionality, but only the method parameters are different, you can use Method Overload. For example:

    Method A, an int parameter.

    void a(int a){}

    The following is to overload the A method and set the parameter A to 1 to achieve the default value.

    void a():a(1){}

  3. Anonymous users2024-02-05

    The argument types are all int types, and you can define a(int a=1){}

    a(string a="1"){}

    So these are two functions.

  4. Anonymous users2024-02-04

    Of course, you can't tell the difference, just call a(1) or a(2) or a(3) directly

  5. Anonymous users2024-02-03

    3. Place all default parameters after the required parameters. For example, in the following method, parameter y is the default parameter and the default value is 10

    public int somemethed(int x, int y = 10)

    When called: int ret = somemethod(10); Using the default parameters, the result is 20;

    ret = somemethod(10, 20);If the default parameter is not used, the result is 30

  6. Anonymous users2024-02-02

    public void test( int v )

    public void test()

    By overloading, you get a method with a default value of 10.

  7. Anonymous users2024-02-01

    Just add = to the end of the argument, but this is a new feature of c and was not supported before.

    void func(int arg1,int arg2=5)

  8. Anonymous users2024-01-31

    The base keyword means to call the parent method with the same name, and you can find the list of arguments of the corresponding method of the parent class in the SDK.

  9. Anonymous users2024-01-30

    If you are with. .net.

    e.g. public static string addstring(string a, string b).

    public static string addstring(string a, string b)

    If you are with. .net, you can overload it as above, or use the new feature in the optional parameter.

    public static string addstring(string a, string b = default value of omitted parameters).

    Note: Optional parameters must have a default value and can only appear after non-optional parameters in the parameter list.

  10. Anonymous users2024-01-29

    public void test( int v )

    public void test()

    By overloading, you get a method with a default value of 10.

  11. Anonymous users2024-01-28

    The function of the out parameter is to give the final value of the method to the out variable after the method is executed.

    If you need a basic array after the method is executed, you can use ref and change all to 0, which should be a problem in the assignment process.

  12. Anonymous users2024-01-27

    Because the for loop is not necessarily entered, when the IDE detects this, it means that if the for loop is not entered, your basic has not been new.

    I could write one last sentence.

    if(base==null)

    base=new ..

  13. Anonymous users2024-01-26

    Optional, if you do not assign a value to this parameter, the value in the signature is used.

  14. Anonymous users2024-01-25

    Optional parameters are specified as default values for specific parameters of a method, which can be omitted when the method is called.

  15. Anonymous users2024-01-24

    The question mark is generic, meaning it can be null or null, which is. The concept proposed later in C has been criticized because C 2003 does not support generics, which can be understood as the class template template< class t > in C++, which uses int?and short?

    When you think they are this type, I don't know much about the specifics, and now I specialize in MFC.

  16. Anonymous users2024-01-23

    The formal arguments are ref and out, you can't replace one of them with a question mark, right?

Related questions
4 answers2024-03-27

define the function void f(int q, int w, int e=0);

e=0 is the default argument, when the function is called f(1,2), then e=0 >>>More

8 answers2024-03-27

You can use function pointers, such as:

voidfunction(int >>>More

5 answers2024-03-27

This is not a parameter definition, but a forced type conversion. Forcibly converts the memory of the new request to the desired type.

3 answers2024-03-27

statement in the defined variables!

14 answers2024-03-27

DefWindowProc and WindowProc are both ** processing message API functions, and DefWindowProc handles messages that are not processed by WindowProc. However, in the scenario of your program, cmfcwnd is a subclass of cframewnd, and only calling defwindowproc cannot achieve all the cframewnd characteristic messages, and you must call the message handler of the parent class.