A C++ Object initialized by another global variable. [on hold]











up vote
-3
down vote

favorite












Hi I am new to C++ but I saw some code that I can not fully understand what happen.



There is a class called MyClass defined and a global variable GVar defined.
Why can you use the GVar to define a class object like this:



int GVar = 1;
const int GVar1 = 10;



MyClass testClass(GVar, GVar1);



What is happening behind the code? Does testClass constructor is called at compile time and passing (1, 10) to the constructor?



Can someone help me please?



Thanks










share|improve this question







New contributor




Nathan Chai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by πάντα ῥεῖ, Jamal 20 mins ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.













  • That is one of many ways to pass arguments to a constructor. Cant determine if it's compile time or not but probably not. This is also not the kind of question we answer here. Please see our help center for more information
    – bruglesco
    18 mins ago















up vote
-3
down vote

favorite












Hi I am new to C++ but I saw some code that I can not fully understand what happen.



There is a class called MyClass defined and a global variable GVar defined.
Why can you use the GVar to define a class object like this:



int GVar = 1;
const int GVar1 = 10;



MyClass testClass(GVar, GVar1);



What is happening behind the code? Does testClass constructor is called at compile time and passing (1, 10) to the constructor?



Can someone help me please?



Thanks










share|improve this question







New contributor




Nathan Chai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by πάντα ῥεῖ, Jamal 20 mins ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.













  • That is one of many ways to pass arguments to a constructor. Cant determine if it's compile time or not but probably not. This is also not the kind of question we answer here. Please see our help center for more information
    – bruglesco
    18 mins ago













up vote
-3
down vote

favorite









up vote
-3
down vote

favorite











Hi I am new to C++ but I saw some code that I can not fully understand what happen.



There is a class called MyClass defined and a global variable GVar defined.
Why can you use the GVar to define a class object like this:



int GVar = 1;
const int GVar1 = 10;



MyClass testClass(GVar, GVar1);



What is happening behind the code? Does testClass constructor is called at compile time and passing (1, 10) to the constructor?



Can someone help me please?



Thanks










share|improve this question







New contributor




Nathan Chai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Hi I am new to C++ but I saw some code that I can not fully understand what happen.



There is a class called MyClass defined and a global variable GVar defined.
Why can you use the GVar to define a class object like this:



int GVar = 1;
const int GVar1 = 10;



MyClass testClass(GVar, GVar1);



What is happening behind the code? Does testClass constructor is called at compile time and passing (1, 10) to the constructor?



Can someone help me please?



Thanks







c++






share|improve this question







New contributor




Nathan Chai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Nathan Chai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Nathan Chai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 21 mins ago









Nathan Chai

1




1




New contributor




Nathan Chai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Nathan Chai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Nathan Chai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by πάντα ῥεῖ, Jamal 20 mins ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by πάντα ῥεῖ, Jamal 20 mins ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.












  • That is one of many ways to pass arguments to a constructor. Cant determine if it's compile time or not but probably not. This is also not the kind of question we answer here. Please see our help center for more information
    – bruglesco
    18 mins ago


















  • That is one of many ways to pass arguments to a constructor. Cant determine if it's compile time or not but probably not. This is also not the kind of question we answer here. Please see our help center for more information
    – bruglesco
    18 mins ago
















That is one of many ways to pass arguments to a constructor. Cant determine if it's compile time or not but probably not. This is also not the kind of question we answer here. Please see our help center for more information
– bruglesco
18 mins ago




That is one of many ways to pass arguments to a constructor. Cant determine if it's compile time or not but probably not. This is also not the kind of question we answer here. Please see our help center for more information
– bruglesco
18 mins ago















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Feedback on college project

Futebolista

Albești (Vaslui)