How can I ensure that correct function is called in case there are multiple candidates

Petr

In C++ is perfectly legitimate to do:

bool x = "hi";

Because "hi" is translated by compiler to a char array and returns a pointer to that array, which is a number and number can be implicitly converted to bool (0 is false, anything else is true).

So I have these ctor:

Exception(QString Text, bool __IsRecoverable = true);
Exception(QString Text, QString _Source, bool __IsRecoverable = true);

Sadly I figured out that calling

Exception *e = new Exception("error happened", "main.cpp @test");

It creates a new instance of "Exception" class which is created using Exception(QString Text, bool __IsRecoverable = true); constructor, which is wrong to a point.

Is there a simple way to ensure that correct function is called, other than restructuring the constructors entirely, changing position of arguments, etc?

Joseph Mansfield

Firstly, I'm not sure why you're dynamically allocating an exception class. I'm not sure that's ever a good idea.

You can explicitly construct a QString:

Exception e("error happened", QString("main.cpp @test"));

Or you can pass the third argument:

Exception e("error happened", "main.cpp @test", true);

Or you can add an additional constructor that takes const char* and will be preferred over the conversion to bool:

Exception(QString Text, const char* Source, bool IsRecoverable = true);

You can easily make this forward to the QString version. Also note that names beginning with an underscore and a capital letter or with two underscores are reserved.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I ensure that correct function is called in case there are multiple candidates

From Dev

How can I ensure that my function is being called and running

From Dev

How can I ensure that the callback for setInterval is called exactly at the interval specified?

From Dev

How do I ensure tearDown is called (in the case of an uncaught exception in the test) with nosetests?

From Java

Rust - How can I return multiple variables from a function such that they are accessible outside the scope the function is called in?

From Dev

How can I ensure a reactjs state is updated, and then call a function?

From Dev

How can I return a called back function?

From Dev

How can I return a called back function?

From Dev

How can i do this by Function correct me

From Dev

How can I ensure I still get correct touch inputs when my scene is offset?

From Dev

How can I stop a long-running function when it is called multiple times?

From Dev

How should I ensure the correct info.plist is used when building app with multiple targets

From Dev

How can I ensure that a method is called (once, if present) for every class in a hierarchy?

From Dev

How can I ensure my application retains focus while SendKeys is called? (Is there a better way than using Sleep?)

From Dev

How can I correct this query that involves a CASE statement for a summary?

From Dev

How can I ensure users enter data in the correct table columns (besides number formatting and magnitude limits)?

From Dev

How can I wirite JUnit test to ensure Arraylist<POJO> records are correct?

From Dev

how can i show the candidates view under the android soft keyboard?

From Dev

How can I create arrays of suitable candidates based on certain criteria?

From Dev

Function is running multiple time as per CPU core(CPU cores = 4 in my case). How can I run function only 1 time?

From Dev

How can I know if a view is called multiple times?

From Dev

How to ensure that a method can only be called from a specific dll

From Dev

How can I check if an anonymous function has been called with NSubstitute?

From Java

How can I test that a function has not been called?

From Dev

How can I get the line number that a function was called from?

From Java

How can I get the arguments called in jest mock function?

From Dev

How can I use $(this) in a function called by the onClick event?

From Dev

How can I modify self in a closure called from a member function?

From Dev

How can I get the line number that a function was called from?

Related Related

  1. 1

    How can I ensure that correct function is called in case there are multiple candidates

  2. 2

    How can I ensure that my function is being called and running

  3. 3

    How can I ensure that the callback for setInterval is called exactly at the interval specified?

  4. 4

    How do I ensure tearDown is called (in the case of an uncaught exception in the test) with nosetests?

  5. 5

    Rust - How can I return multiple variables from a function such that they are accessible outside the scope the function is called in?

  6. 6

    How can I ensure a reactjs state is updated, and then call a function?

  7. 7

    How can I return a called back function?

  8. 8

    How can I return a called back function?

  9. 9

    How can i do this by Function correct me

  10. 10

    How can I ensure I still get correct touch inputs when my scene is offset?

  11. 11

    How can I stop a long-running function when it is called multiple times?

  12. 12

    How should I ensure the correct info.plist is used when building app with multiple targets

  13. 13

    How can I ensure that a method is called (once, if present) for every class in a hierarchy?

  14. 14

    How can I ensure my application retains focus while SendKeys is called? (Is there a better way than using Sleep?)

  15. 15

    How can I correct this query that involves a CASE statement for a summary?

  16. 16

    How can I ensure users enter data in the correct table columns (besides number formatting and magnitude limits)?

  17. 17

    How can I wirite JUnit test to ensure Arraylist<POJO> records are correct?

  18. 18

    how can i show the candidates view under the android soft keyboard?

  19. 19

    How can I create arrays of suitable candidates based on certain criteria?

  20. 20

    Function is running multiple time as per CPU core(CPU cores = 4 in my case). How can I run function only 1 time?

  21. 21

    How can I know if a view is called multiple times?

  22. 22

    How to ensure that a method can only be called from a specific dll

  23. 23

    How can I check if an anonymous function has been called with NSubstitute?

  24. 24

    How can I test that a function has not been called?

  25. 25

    How can I get the line number that a function was called from?

  26. 26

    How can I get the arguments called in jest mock function?

  27. 27

    How can I use $(this) in a function called by the onClick event?

  28. 28

    How can I modify self in a closure called from a member function?

  29. 29

    How can I get the line number that a function was called from?

HotTag

Archive