English 中文(简体)
职 论
原标题:Function arguments
  • 时间:2012-01-13 19:13:31
  •  标签:
  • c++
  • syntax

我不理解这一守则为何奏效。

int f(int,int);

int main()
{
    f(12,21);
    return 0;
}

int f(int,int b)
{
    return 0;
}

如何在职能 f(......)中首先发挥杠杆作用?

最佳回答

参数名称不属于功能签名的一部分,其名称和参数类型仅为。

Therefore, it s perfectly legal not naming your parameters. However, you can t use them. (unless of course you do some hacking)

www.un.org/Depts/DGACM/index_spanish.htm 一些 ha: 注——不是独立平台,不受标准保障,而是:

void foo (int x, int, int z)
{
   int* pz = &z;
   int y = *(--pz);
   cout << x << " " << y << " " << z;
}

int main()
{
    foo(2,3,4);
    // prints "2 3 4"
}

2008年,与MSVS合作,在Win7为我工作。 守则取决于如何将参数推向职能论点。

在生产法典中,你应使用包括申报在内的所有参数的名称,并尽可能加以描述。

问题回答

你们可以 t。 除非你给它一个名字。 但是,你没有利用这一职能。

通常,该论点的名称被遗漏,以避免对其未使用提出警告。 在<代码>f功能中,你可能再次被警告到<代码>b未使用,但不是第一个论点。

you cannot use the first argument of f(...). The missing variable name tells the compiler you explicetly want to ignore this parameter.

虽然从一看这似乎并不可行,但事实上,当你需要跟踪(例如,由于虚拟方法)时,你的职能根本不关心从打电话者那里获得的一切。

简单例子:

class Painter {
public:
   virtual void paint( Object o, viewscreen * screen ) = 0;
};

class WindowPainter {
public:
   virtual void paint( Object o, viewscreen * screen ) {
   ...
   }
};

class ConsolePainter {
public:
   // The console is available as std::cout globaly
   // often the name is just put in comments, to reference the common api  
   virtual void paint( Object o, viewscreen * /* screen */) {
   ...
   }
};

http://em>can t利用这一初步论点。 最初的C语定义对类似情况极为宽容。 仅仅因为你可以这样做,就意味着有任何有益的理由。

你不能在职能中使用第一种论点,你没有。 因此,该法典发挥了作用。

如果你不使用,功能参数就不需要名称。

如果你想利用第一个论点,那么就给它一个名字:

int f(int a,int b)
{
    return 0;
}

你们很少看到在职能定义中这样做,但在声明中则更为常见。

例如,如果你重新“拆除”建筑商,那么在命名参数方面就没有点:

obj& operator=(const obj&) = delete;




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签