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











up vote
-5
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 2 days 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
    2 days ago










  • where should I post the question then.
    – Nathan Chai
    2 days ago










  • If you rephrase it to be on-topic over at Stack Overflow then I believe you will find it is a duplicate. I would therefor suggest you try reading every SO question you can find under the [c++] tag about constructors, how they work, how passing arguments to constructors as well as functions works including passing rvalues and lvalues.
    – bruglesco
    2 days ago















up vote
-5
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 2 days 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
    2 days ago










  • where should I post the question then.
    – Nathan Chai
    2 days ago










  • If you rephrase it to be on-topic over at Stack Overflow then I believe you will find it is a duplicate. I would therefor suggest you try reading every SO question you can find under the [c++] tag about constructors, how they work, how passing arguments to constructors as well as functions works including passing rvalues and lvalues.
    – bruglesco
    2 days ago













up vote
-5
down vote

favorite









up vote
-5
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 2 days 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 2 days 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 2 days 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
    2 days ago










  • where should I post the question then.
    – Nathan Chai
    2 days ago










  • If you rephrase it to be on-topic over at Stack Overflow then I believe you will find it is a duplicate. I would therefor suggest you try reading every SO question you can find under the [c++] tag about constructors, how they work, how passing arguments to constructors as well as functions works including passing rvalues and lvalues.
    – bruglesco
    2 days 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
    2 days ago










  • where should I post the question then.
    – Nathan Chai
    2 days ago










  • If you rephrase it to be on-topic over at Stack Overflow then I believe you will find it is a duplicate. I would therefor suggest you try reading every SO question you can find under the [c++] tag about constructors, how they work, how passing arguments to constructors as well as functions works including passing rvalues and lvalues.
    – bruglesco
    2 days 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
2 days 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
2 days ago












where should I post the question then.
– Nathan Chai
2 days ago




where should I post the question then.
– Nathan Chai
2 days ago












If you rephrase it to be on-topic over at Stack Overflow then I believe you will find it is a duplicate. I would therefor suggest you try reading every SO question you can find under the [c++] tag about constructors, how they work, how passing arguments to constructors as well as functions works including passing rvalues and lvalues.
– bruglesco
2 days ago




If you rephrase it to be on-topic over at Stack Overflow then I believe you will find it is a duplicate. I would therefor suggest you try reading every SO question you can find under the [c++] tag about constructors, how they work, how passing arguments to constructors as well as functions works including passing rvalues and lvalues.
– bruglesco
2 days ago















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Quarter-circle Tiles

build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

Mont Emei