Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong virtual method override called. #28

Closed
vgvassilev opened this issue Sep 13, 2014 · 0 comments
Closed

Wrong virtual method override called. #28

vgvassilev opened this issue Sep 13, 2014 · 0 comments

Comments

@vgvassilev
Copy link
Owner

class A {
public:
  virtual float vm(float x, float y) {
    return x + y;
  }
};
class B : public A {
public:
  float vm(float x, float y) override {
    return x*x + y*y;
  }
};
int main() {
  auto vm_darg0_A = clad::differentiate(&A::vm, 0);
  printf("Result is = %f\n", vm_darg0_A.execute(a, 2, 3)); // CHECK-EXEC: Result is = 1.0000
  auto vm_darg0_B = clad::differentiate(&B::vm, 0);
  printf("Result is = %f\n", vm_darg0_B.execute(b, 2, 3)); // CHECK-EXEC: Result is = 4.0000
}

For some reason vm_darg0_A.execute(a, 2, 3) calls the B::vm. If the execute()-s get swapped it works as expected.

@vgvassilev vgvassilev added the bug label Sep 13, 2014
@vgvassilev vgvassilev self-assigned this Sep 13, 2014
alexander-penev added a commit to alexander-penev/clad that referenced this issue Feb 1, 2022
…silev#28

We can differentiate virtual class functions with several caveats:
```
struct A {
  virtual double f(double x) {}
  virtual double f_darg0(double x); // clad will provide a definition
};
alexander-penev added a commit to alexander-penev/clad that referenced this issue Feb 1, 2022
…silev#28

We can differentiate virtual class functions with several caveats:
```
struct A {
  virtual double f(double x) {}
  virtual double f_darg0(double x); // clad will provide a definition
};
alexander-penev added a commit to alexander-penev/clad that referenced this issue Feb 2, 2022
…silev#28

We can differentiate virtual class functions with several caveats:
```
struct A {
  virtual double f(double x) {}
  virtual double f_darg0(double x); // clad will provide a definition
};
parth-07 pushed a commit to parth-07/clad that referenced this issue Feb 22, 2022
…silev#28

We can differentiate virtual class functions with several caveats:
```
struct A {
  virtual double f(double x) {}
  virtual double f_darg0(double x); // clad will provide a definition
};
parth-07 pushed a commit to parth-07/clad that referenced this issue Feb 24, 2022
…silev#28

We can differentiate virtual class functions with several caveats:
```
struct A {
  virtual double f(double x) {}
  virtual double f_darg0(double x); // clad will provide a definition
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant