Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8933711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:36:45+00:00 2026-06-15T09:36:45+00:00

class Method { public: virtual void Rum(); }; class Euler : public Method {

  • 0
class Method {
  public:    
  virtual void Rum();
};
class Euler : public Method {
  virtual void Rum() {
    printf("ahoj\n");
  }    
};
class Kutta : public Method {
  virtual void Rum() {
    printf("ahoj2\n");
  }    
};
class Simulator {
  public:
  Method *pointer;
  Simulator();
  void setmethod(Method m) { pointer = &m; }
};

int main() {
  Simulator s;
  s.setmethod(new Kutta());
  s.pointer->Rum();
  s.setmethod(new Euler());
  s.pointer->Rum();
}

I hope this example understandable enough. I tried to apply the principle of inheritance but I get these errors: (OOP stuff seems to be a little bit messed in my head)

prog.cpp: In function ‘int main()’:
prog.cpp:26: error: no matching function for call to ‘Simulator::setmethod(Kutta*)’
prog.cpp:21: note: candidates are: void Simulator::setmethod(Method)
prog.cpp:28: error: no matching function for call to ‘Simulator::setmethod(Euler*)’
prog.cpp:21: note: candidates are: void Simulator::setmethod(Method)

So what is the correct way to pass child instead of its parent? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:36:48+00:00Added an answer on June 15, 2026 at 9:36 am

    Signature of your void setmethod(Method m) isn’t correct. It must be void setmethod(Method* m) to match your invocation.

    As a side note, you need a reference or a pointer in your method for the polymorphism to work – that means that you can’t pass the argument to setmethod by value and expect the polymorphism to work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have base class A public class A { public virtual void Method(A parameter)
I have seen this question http://www.careercup.com/question?id=384062 class Base { public : virtual void method
class IEmployeeServiceProxy { public: virtual ~IEmployeeServiceProxy() { } virtual void AddEmployee(const Employee&) = 0;
I currently have this method header: public virtual void SetupGrid<T>() where T : class,
The class mshtml.HTMLDocumentClass in Microsoft.mshtml.dll assembly has a method: public virtual void write(params object[]
consider the following program: class Base { public: virtual void foo() const { cout
public Class Test{ GetDataset(RandomBoolean uncertain); GetDataset2(); GetDataset3(); } where method definitions are public virtual
In C++, you can do the following: class base_class { public: virtual void do_something()
Imagine a base class with many constructors and a virtual method public class Foo
Shape.h namespace Graphics { class Shape { public: virtual void Render(Point point) {}; };

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.