I have a question related to the previous question posted here Static Field Initialization Procedure Suppose I have the following structure with two static members xand y(the templates themselves)
x
y
#include <iostream> using namespace std; template <typename T> struct Foo { static T x; static T y; Foo() { cout << "x = " << x << endl; cout << "y = " << y << endl; } }; template <typename T> T Foo<T>::x = 1.1f; template <typename T> T Foo<T>::y = 2.0 * Foo<T>::x; int main() { Foo<double> foo; }
Output:
x = 1.1 y = 2.2
I initialize xand yabove main(), and you can see what ydepends on x, so it is better to initialize first x.
main()
My questions:
Foo<double> foo;
!
, Foo<double>::x , Foo<double>::y .
Foo<double>::x
Foo<double>::y
3.6.2/2:
:..., , , ., - ; - . .
:
...
, , , .
, - ; - . .
, :
double tmp = 1.1; template <typename T> T Foo<T>::x = tmp; template <typename T> T Foo<T>::y = 2.0 * Foo<T>::x;
"" - Foo<double>::y 2.2, 0.0 ( , tmp ).
2.2
0.0
tmp
Source: https://habr.com/ru/post/1617404/More articles:Удалите Pycharm полностью, Ubuntu - ubuntuHow to determine form field type in php - phpRepeating the classic repetition of the fiasco initialization order C ++ - c ++Can't figure out how to check if list contains 0 - c #Execution failed for task ': app: transformClassesWithDexForDebug' - androidConnect multiple computers to the same Mac Xamarin agent on Apple - ioshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1617421/conversion-of-scala-class-to-javascript-using-jscala&usg=ALkJrhg_8qgvyRfhSbWARsVHnbDU_lpSSQWhen adding values remain in place - javascripthow to update my dropdown based on another dropdown - jsonPL \ SQL XMLTable Performance - oracleAll Articles