x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Cannot overload operator: 'operator <<' is ambiguous

I'm trying to overload the << operator, as per Rama's wiki tutorial about binary saving, so that I can save a custom object to binary.

I have created a separate header file for operator overloading called FileOperators.h which contains this:

 FORCEINLINE FArchive& operator<<(FArchive& Ar, USettings* Settings)
 {
     if (!Settings) return Ar;
 
     Ar << Settings->ObjectClass;
 
     return Ar;
 }

So it should save the ObjectClass parameter (UClass*) to binary. And I have created a function trying to use that (I'm only putting the relavant line in here)

 void UFileSystem::SaveLoadData(FArchive& Ar, USettings* Settings)
 {
     Ar << Settings;
 }

When I try to compile, I get the error: 'operator <<' is ambiguous

If I mouse over the << operator, it tells me why:

 more than one operator "<<" matches these operands:
 function "operator<<(FArchive &Ar, USettings *&Res)"
 function "operator<<(FArchive &Ar, USettings *Settings)"
 oparand types are: FArchive << USettings*

What am I doing wrong? I can't see that I'm doing anything differently from Rama's code...

Product Version: UE 4.17
Tags:
more ▼

asked Oct 24 '17 at 08:53 PM in C++ Programming

avatar image

localstarlight
58 15 21 28

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

I figure it out.

The operator override needed to be

USettings& Settings

not

USettings* Settings

And the use of the operator needed to be:

Ar << *Settings

not

Ar << Settings

more ▼

answered Oct 25 '17 at 07:52 AM

avatar image

localstarlight
58 15 21 28

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question