Use of overloaded operator ambiguous

Malachi

The following code:

typedef void HELPER;

const HELPER* helper = _helper;

inline ostream& operator <<(ostream& out,  const HELPER* arg) 
{ out << (const char*)(arg); return out; }

Blows up if I attempt a

cout << helper;

Specifically, I get:

main.cpp:35:28: error: use of overloaded operator '<<' is ambiguous (with operand types 'basic_ostream >' and 'const HELPER *' (aka 'const void *'))

and it lists a few candidates:

/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/ostream:207:0: note: candidate function
    basic_ostream& operator<<(const void* __p);
                   ^
main.cpp:25:17: note: candidate function
inline ostream& operator <<(ostream& out,  const HELPER* arg) 
                ^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/ostream:195:20: note: candidate function
    basic_ostream& operator<<(bool __n);
                   ^

I'm a little surprised that my typedef isn't invoking a stronger type matching here. How can I get this operator overload running?

EDIT: Further clarification, the purpose of this code is that I am dual-targeting a set of Arduino libraries. They manage their strings frequently with:

typedef void __FlashStringHelper;

void showHelp(const __FlashStringHelper* helpText)
{
   Serial.print(helpText);
}

I like iostream and planned on this dual target, so I overloaded << on Serial object and made the previous into (this is the oversimplified version, for example)

#define cout Serial

void showHelp(const __FlashStringHelper* helpText)
{
   cout << helpText;
}

Now I want to actually target real iostream for a different arch, but the old Arduino code can't vary (much) from its __FlashStringHelpers. That's where I'm at

Owen Delahoy

typedef doesn't create types it aliases them,

inline ostream& operator <<(ostream& out,  const HELPER* arg) 

is equivalent to

inline ostream& operator <<(ostream& out,  const void* arg)

Maybe you wanted to create a type named HELPER

class HELPER{};

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Eigen with custom scalar types: Matrix multiplication with custom type fails with `use of overloaded operator '*' is ambiguous`

分類Dev

error: call of overloaded distance is ambiguous

分類Dev

numpy elementwise comparison with overloaded operator

分類Dev

Ambiguous use of 'observeSingleEvent(of: with:)

分類Dev

Why is my overloaded multiplication operator not recognized?

分類Dev

C++ Overloaded Output Operator with Template

分類Dev

Sort STL list with single overloaded operator <

分類Dev

ambiguous use of selector dataTask(with: completionHandler:)

分類Dev

Ambiguous use of init in Swift 2.2

分類Dev

Should the bracket overloaded operator in C++ be declared as a const function?

分類Dev

Array of pointers to the base class that contains objects of derived classes and overloaded << operator

分類Dev

ambiguous call to overloaded function with "bind" when i add header file"boost/function"

分類Dev

Does an overloaded bitwise-or operator ('|') have a well-defined evaluation-order?

分類Dev

Swift 3 and Xcode8 - Ambiguous use of init

分類Dev

How to use arrow function with || operator

分類Dev

Ansible - how to use when with an or operator

分類Dev

How to use map operator as mergeMap?

分類Dev

Use of Logical Operator in Loop Condition

分類Dev

how to use "like" operator in android?

分類Dev

Cannot use 'in' operator to search for '728' in

分類Dev

How to use the ternary operator inside an interpolated string?

分類Dev

What use does the == operator have for String?

分類Dev

Laravel Eloquent how to use between operator

分類Dev

'Can't use in/contains operator with collection'

分類Dev

Only use $in operator if a certain condition is met - Mongoose

分類Dev

How to you use operator Int() of QFlags?

分類Dev

How to use an operator in where clause with an optional include?

分類Dev

correct use of retryWhen operator with RxSwift 4.0.0

分類Dev

Is it possible to use string interpolation with the pipe operator?

Related 関連記事

  1. 1

    Eigen with custom scalar types: Matrix multiplication with custom type fails with `use of overloaded operator '*' is ambiguous`

  2. 2

    error: call of overloaded distance is ambiguous

  3. 3

    numpy elementwise comparison with overloaded operator

  4. 4

    Ambiguous use of 'observeSingleEvent(of: with:)

  5. 5

    Why is my overloaded multiplication operator not recognized?

  6. 6

    C++ Overloaded Output Operator with Template

  7. 7

    Sort STL list with single overloaded operator <

  8. 8

    ambiguous use of selector dataTask(with: completionHandler:)

  9. 9

    Ambiguous use of init in Swift 2.2

  10. 10

    Should the bracket overloaded operator in C++ be declared as a const function?

  11. 11

    Array of pointers to the base class that contains objects of derived classes and overloaded << operator

  12. 12

    ambiguous call to overloaded function with "bind" when i add header file"boost/function"

  13. 13

    Does an overloaded bitwise-or operator ('|') have a well-defined evaluation-order?

  14. 14

    Swift 3 and Xcode8 - Ambiguous use of init

  15. 15

    How to use arrow function with || operator

  16. 16

    Ansible - how to use when with an or operator

  17. 17

    How to use map operator as mergeMap?

  18. 18

    Use of Logical Operator in Loop Condition

  19. 19

    how to use "like" operator in android?

  20. 20

    Cannot use 'in' operator to search for '728' in

  21. 21

    How to use the ternary operator inside an interpolated string?

  22. 22

    What use does the == operator have for String?

  23. 23

    Laravel Eloquent how to use between operator

  24. 24

    'Can't use in/contains operator with collection'

  25. 25

    Only use $in operator if a certain condition is met - Mongoose

  26. 26

    How to you use operator Int() of QFlags?

  27. 27

    How to use an operator in where clause with an optional include?

  28. 28

    correct use of retryWhen operator with RxSwift 4.0.0

  29. 29

    Is it possible to use string interpolation with the pipe operator?

ホットタグ

アーカイブ