更新时间:2021-08-07 05:39:21
我认为,它们被声明为函数的参数。
I think, they were declared like parameters of the function.
你在哪里看到它们在这个函数中声明了?
Where do you see them declared in this function ?
T show()
{
return(x>y)?x:y;
}
可能你应该使用 a
和 b
而不是?
[更新]
May be you should use a
and b
instead ?
[Update]
它们被声明用于设置函数。
为什么我不能使用其他变量?
they are declared for set function.
and why can't i use other variables?
它们仅在set函数中声明为set函数。
[更新]
在 show
中,您可以使用 a
和 b
因为你在类定义中声明了它们。
They declared in set function for set function only.
[Update]
In show
, you can use a
and b
because you declared them in class definition.
class myMax{
T a,b;
您要显示的代码,
The code that you are showing,
T show()
{
return(x>y)?x:y;
}
无效,通过查看类定义(看看成员!)。您只定义了a和b作为类中的属性,x和y未赋予任何类型,因此在给定范围内没有定义。
Is invalid, by looking at the class definition (have a look at the members!). You have defined only a and b to be properties in the class, x and y are not given to be of any type, and thus no defined in the given scope.
只有a和b工作。
这是因为a和b被定义为属性(类别 T
类中的(成员)。这完美地执行。因为编译器知道要使用的类型以及在作用域中定义它们的位置(作为成员)。
解决这个问题的方法就是使用a和b名称。不要使用x和y;因为这也需要更改类定义!
That is because a and b are defined as properties (members) in your class of type T
. That executes perfectly. Because compiler knows what type to use and where they are defined in the scope (as the members).
Solution to this problem is to just use the a and b names. Don't use the x and y; because that would require to change the class definition too!
不是解决方案,而是链接到好的讲座。
开始C书,C语言是C ++的始祖。大多数C适用于C ++。
C编程语言 - ***,免费的百科全书 [ ^ ]
https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2.pdf [ ^ ]
http://www.ime.usp.br/~pf/Kernighan-Ritchie/C- Programming-Ebook.pdf [ ^ ]
C ++编程语言 [ ^ ]
[更新]
学习一些分析方法, Dijkstra自上而下方法是一个好的开始。
它将帮助您设备结构化算法。
https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design [ ^ ]
https://en.wikipedia.org/wiki/Structured_programming [ ^ ]
https://en.wikipedia.org/wiki/Edsger_W._Dijkstra [ ^ ]
https: //www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF [ ^ ]
Not a solution, but links to good lectures.
Start with the C book, C language is the ancestor of C++. Most of C apply to C++.
The C Programming Language - Wikipedia, the free encyclopedia[^]
https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2.pdf[^]
http://www.ime.usp.br/~pf/Kernighan-Ritchie/C-Programming-Ebook.pdf[^]
C++ Programing Language[^]
[Update]
Learn some analyze method, Dijkstra Top-Down method is a good start.
It will help you to device structured algorithms.
https://en.wikipedia.org/wiki/Top-down_and_bottom-up_design[^]
https://en.wikipedia.org/wiki/Structured_programming[^]
https://en.wikipedia.org/wiki/Edsger_W._Dijkstra[^]
https://www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF[^]