I am writing a custom iterator template and template container class.
Below is an example set of methods I am using. In my main method, however, when I want to invoke these methods. I am using the full name rather than just the operator, take _RBIterator& operator++() for example.
1 2 3 4 5 6 7 8 9
auto s = rb.begin();
s.operator++();
Rather than :
auto s = rb.begin();
++s;
Second example using ==
1 2 3 4 5 6 7 8 9 10 11 12
auto one = rb.begin();
auto two = rb.begin();
std::cout << " Equal? : " << one.operator==(two);
Rather than:
auto one = rb.begin();
auto two = rb.begin();
std::cout << " Equal? : " << one == two ;
Is my syntax correct? I have to call the method full name as shown in the first example rather than the second. Looking at examples online others have overloaded there operators in this way ( writing operator in front over the actual operator symbols ) see :
I don't see any examples of writing out the "full name" (as you call it) in your stackoverflow link. It is pointless to do so, however. Just write it normally.
And your first example isn't even correct since s.operator++() is pre-increment whereas your "rather than" example shows a post-increment.
Yes sorry, my mistake re the post and pre-increment and The StackOverflow is probably not a good example as they are not showing the main method where they are implementing their template.
It is pointless to do so, however. Just write it normally.
This is my point, I am unable to write it "normally".
If something isn't compiling, try to produce a minimal example that reproduces the compile errors.
Edit: For example,
1 2 3 4 5 6 7 8 9 10 11 12
// Example program
#include <iostream>
#include <string>
int main()
{
std::string name = "Billy";
auto one = name.begin();
auto two = name.begin();
std::cout << one == two;
}
I'll admit the error it produces is convoluted, but the issue is operator precedence.
This is an unfortunate consequence of Stroustrup overloading the bit shift operators for stream operators.
Change it to:
1 2 3 4 5 6 7 8 9 10 11 12
// Example program
#include <iostream>
#include <string>
int main()
{
std::string name = "Billy";
auto one = name.begin();
auto two = name.begin();
std::cout << (one == two);
}
> This is my point, I am unable to write it "normally".
> The main class will only compile if I write out
> .operator++()
> rather than
> ++rb;
that should have been your first post
and if you get an error message, then post it (with templates the message may be quite long, grep the line that says error)