Why is Polymorphism is needed when we have the keyword “auto” in C++












0














Correct me if i'm wrong, but the keyword "auto" can solve all the problems that polymorphism was invented to solve.



instead of declaring of virtual function func of class A, when we have Class B inheriting from it, we can just say that the function func is receiving auto param, and it will know what case to trigger.



What do i miss?










share|improve this question


















  • 1




    Correct me if i'm wrong, but the keyword "auto" can solve all the problems that polymorphism was invented to solve. You're wrong. Try for example std::vector<auto*>
    – tkausl
    Nov 19 '18 at 16:11






  • 2




    You should list the problems that polymorphism (built-in runtime polymorphism in case of virtual functions being involved) was invented to solve and explain for each problem how it could be solved with auto. Your current "just say that the function func is receiving auto param" makes no sense.
    – VTT
    Nov 19 '18 at 16:17


















0














Correct me if i'm wrong, but the keyword "auto" can solve all the problems that polymorphism was invented to solve.



instead of declaring of virtual function func of class A, when we have Class B inheriting from it, we can just say that the function func is receiving auto param, and it will know what case to trigger.



What do i miss?










share|improve this question


















  • 1




    Correct me if i'm wrong, but the keyword "auto" can solve all the problems that polymorphism was invented to solve. You're wrong. Try for example std::vector<auto*>
    – tkausl
    Nov 19 '18 at 16:11






  • 2




    You should list the problems that polymorphism (built-in runtime polymorphism in case of virtual functions being involved) was invented to solve and explain for each problem how it could be solved with auto. Your current "just say that the function func is receiving auto param" makes no sense.
    – VTT
    Nov 19 '18 at 16:17
















0












0








0







Correct me if i'm wrong, but the keyword "auto" can solve all the problems that polymorphism was invented to solve.



instead of declaring of virtual function func of class A, when we have Class B inheriting from it, we can just say that the function func is receiving auto param, and it will know what case to trigger.



What do i miss?










share|improve this question













Correct me if i'm wrong, but the keyword "auto" can solve all the problems that polymorphism was invented to solve.



instead of declaring of virtual function func of class A, when we have Class B inheriting from it, we can just say that the function func is receiving auto param, and it will know what case to trigger.



What do i miss?







c++ oop polymorphism






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 16:10









Or251

1829




1829








  • 1




    Correct me if i'm wrong, but the keyword "auto" can solve all the problems that polymorphism was invented to solve. You're wrong. Try for example std::vector<auto*>
    – tkausl
    Nov 19 '18 at 16:11






  • 2




    You should list the problems that polymorphism (built-in runtime polymorphism in case of virtual functions being involved) was invented to solve and explain for each problem how it could be solved with auto. Your current "just say that the function func is receiving auto param" makes no sense.
    – VTT
    Nov 19 '18 at 16:17
















  • 1




    Correct me if i'm wrong, but the keyword "auto" can solve all the problems that polymorphism was invented to solve. You're wrong. Try for example std::vector<auto*>
    – tkausl
    Nov 19 '18 at 16:11






  • 2




    You should list the problems that polymorphism (built-in runtime polymorphism in case of virtual functions being involved) was invented to solve and explain for each problem how it could be solved with auto. Your current "just say that the function func is receiving auto param" makes no sense.
    – VTT
    Nov 19 '18 at 16:17










1




1




Correct me if i'm wrong, but the keyword "auto" can solve all the problems that polymorphism was invented to solve. You're wrong. Try for example std::vector<auto*>
– tkausl
Nov 19 '18 at 16:11




Correct me if i'm wrong, but the keyword "auto" can solve all the problems that polymorphism was invented to solve. You're wrong. Try for example std::vector<auto*>
– tkausl
Nov 19 '18 at 16:11




2




2




You should list the problems that polymorphism (built-in runtime polymorphism in case of virtual functions being involved) was invented to solve and explain for each problem how it could be solved with auto. Your current "just say that the function func is receiving auto param" makes no sense.
– VTT
Nov 19 '18 at 16:17






You should list the problems that polymorphism (built-in runtime polymorphism in case of virtual functions being involved) was invented to solve and explain for each problem how it could be solved with auto. Your current "just say that the function func is receiving auto param" makes no sense.
– VTT
Nov 19 '18 at 16:17














1 Answer
1






active

oldest

votes


















10














No, auto cannot solve any of those problems.



auto is a compile-time utility to deduce the type of a thing from the code that's around it. It is more closely related to templates (indeed, the auto in the parameter list of a lambda is implemented by a template!).



It has no knowledge of runtime states and cannot be used to perform virtual dispatch.



These are completely different concepts and your best bet would be to re-study what each one means.






share|improve this answer





















  • Thank you. I was told that auto has runtime knowledge.
    – Or251
    Nov 19 '18 at 16:19










  • And auto variables use (slightly addended) template type deduction to tun into a concrete type.
    – Quentin
    Nov 19 '18 at 16:19






  • 2




    @Or251 Tell whoever told you that to come here for a lesson ;)
    – Lightness Races in Orbit
    Nov 19 '18 at 16:22






  • 1




    @Or251 ... or, print the current standard draft and hit said person hard with it. (For best effect not only print the relevant section but the whole draft ;)
    – Swordfish
    Nov 19 '18 at 16:27













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378612%2fwhy-is-polymorphism-is-needed-when-we-have-the-keyword-auto-in-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









10














No, auto cannot solve any of those problems.



auto is a compile-time utility to deduce the type of a thing from the code that's around it. It is more closely related to templates (indeed, the auto in the parameter list of a lambda is implemented by a template!).



It has no knowledge of runtime states and cannot be used to perform virtual dispatch.



These are completely different concepts and your best bet would be to re-study what each one means.






share|improve this answer





















  • Thank you. I was told that auto has runtime knowledge.
    – Or251
    Nov 19 '18 at 16:19










  • And auto variables use (slightly addended) template type deduction to tun into a concrete type.
    – Quentin
    Nov 19 '18 at 16:19






  • 2




    @Or251 Tell whoever told you that to come here for a lesson ;)
    – Lightness Races in Orbit
    Nov 19 '18 at 16:22






  • 1




    @Or251 ... or, print the current standard draft and hit said person hard with it. (For best effect not only print the relevant section but the whole draft ;)
    – Swordfish
    Nov 19 '18 at 16:27


















10














No, auto cannot solve any of those problems.



auto is a compile-time utility to deduce the type of a thing from the code that's around it. It is more closely related to templates (indeed, the auto in the parameter list of a lambda is implemented by a template!).



It has no knowledge of runtime states and cannot be used to perform virtual dispatch.



These are completely different concepts and your best bet would be to re-study what each one means.






share|improve this answer





















  • Thank you. I was told that auto has runtime knowledge.
    – Or251
    Nov 19 '18 at 16:19










  • And auto variables use (slightly addended) template type deduction to tun into a concrete type.
    – Quentin
    Nov 19 '18 at 16:19






  • 2




    @Or251 Tell whoever told you that to come here for a lesson ;)
    – Lightness Races in Orbit
    Nov 19 '18 at 16:22






  • 1




    @Or251 ... or, print the current standard draft and hit said person hard with it. (For best effect not only print the relevant section but the whole draft ;)
    – Swordfish
    Nov 19 '18 at 16:27
















10












10








10






No, auto cannot solve any of those problems.



auto is a compile-time utility to deduce the type of a thing from the code that's around it. It is more closely related to templates (indeed, the auto in the parameter list of a lambda is implemented by a template!).



It has no knowledge of runtime states and cannot be used to perform virtual dispatch.



These are completely different concepts and your best bet would be to re-study what each one means.






share|improve this answer












No, auto cannot solve any of those problems.



auto is a compile-time utility to deduce the type of a thing from the code that's around it. It is more closely related to templates (indeed, the auto in the parameter list of a lambda is implemented by a template!).



It has no knowledge of runtime states and cannot be used to perform virtual dispatch.



These are completely different concepts and your best bet would be to re-study what each one means.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 16:11









Lightness Races in Orbit

284k51460781




284k51460781












  • Thank you. I was told that auto has runtime knowledge.
    – Or251
    Nov 19 '18 at 16:19










  • And auto variables use (slightly addended) template type deduction to tun into a concrete type.
    – Quentin
    Nov 19 '18 at 16:19






  • 2




    @Or251 Tell whoever told you that to come here for a lesson ;)
    – Lightness Races in Orbit
    Nov 19 '18 at 16:22






  • 1




    @Or251 ... or, print the current standard draft and hit said person hard with it. (For best effect not only print the relevant section but the whole draft ;)
    – Swordfish
    Nov 19 '18 at 16:27




















  • Thank you. I was told that auto has runtime knowledge.
    – Or251
    Nov 19 '18 at 16:19










  • And auto variables use (slightly addended) template type deduction to tun into a concrete type.
    – Quentin
    Nov 19 '18 at 16:19






  • 2




    @Or251 Tell whoever told you that to come here for a lesson ;)
    – Lightness Races in Orbit
    Nov 19 '18 at 16:22






  • 1




    @Or251 ... or, print the current standard draft and hit said person hard with it. (For best effect not only print the relevant section but the whole draft ;)
    – Swordfish
    Nov 19 '18 at 16:27


















Thank you. I was told that auto has runtime knowledge.
– Or251
Nov 19 '18 at 16:19




Thank you. I was told that auto has runtime knowledge.
– Or251
Nov 19 '18 at 16:19












And auto variables use (slightly addended) template type deduction to tun into a concrete type.
– Quentin
Nov 19 '18 at 16:19




And auto variables use (slightly addended) template type deduction to tun into a concrete type.
– Quentin
Nov 19 '18 at 16:19




2




2




@Or251 Tell whoever told you that to come here for a lesson ;)
– Lightness Races in Orbit
Nov 19 '18 at 16:22




@Or251 Tell whoever told you that to come here for a lesson ;)
– Lightness Races in Orbit
Nov 19 '18 at 16:22




1




1




@Or251 ... or, print the current standard draft and hit said person hard with it. (For best effect not only print the relevant section but the whole draft ;)
– Swordfish
Nov 19 '18 at 16:27






@Or251 ... or, print the current standard draft and hit said person hard with it. (For best effect not only print the relevant section but the whole draft ;)
– Swordfish
Nov 19 '18 at 16:27




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378612%2fwhy-is-polymorphism-is-needed-when-we-have-the-keyword-auto-in-c%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

A Topological Invariant for $pi_3(U(n))$