| View previous topic :: View next topic |
| Author |
Message |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Tue Apr 21, 2009 2:15 am Post subject: custom operator |
|
|
Hey there.
I tried to overload an operator but it freaked out on me so how do I create a new one?
_________________
Intel over amd yes. |
|
| Back to top |
|
 |
Zerith Master Cheater
Reputation: 1
Joined: 07 Oct 2007 Posts: 468
|
Posted: Tue Apr 21, 2009 3:04 am Post subject: |
|
|
| you can't create a fully new operator, though you can overload one only for classes,enums etc. not native types.
|
|
| Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Tue Apr 21, 2009 3:44 am Post subject: |
|
|
| Zerith wrote: | | you can't create a fully new operator, though you can overload one only for classes,enums etc. not native types. |
the operator i want to overload aint overloadable so that's not an option.
_________________
Intel over amd yes. |
|
| Back to top |
|
 |
Zerith Master Cheater
Reputation: 1
Joined: 07 Oct 2007 Posts: 468
|
Posted: Tue Apr 21, 2009 4:25 am Post subject: |
|
|
| what do you mean isn't overloadable? everything is overloadable.
|
|
| Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Tue Apr 21, 2009 7:16 am Post subject: |
|
|
| Zerith wrote: | | what do you mean isn't overloadable? everything is overloadable. |
Oh, great. Is that why visual studio told me that it isn't overloadable? I'll try again.
Edit :
What is this! Now i get other errors.
_________________
Intel over amd yes. |
|
| Back to top |
|
 |
Zerith Master Cheater
Reputation: 1
Joined: 07 Oct 2007 Posts: 468
|
Posted: Tue Apr 21, 2009 8:42 am Post subject: |
|
|
| wallantia wrote: | | Zerith wrote: | | what do you mean isn't overloadable? everything is overloadable. |
Oh, great. Is that why visual studio told me that it isn't overloadable? I'll try again.
Edit :
What is this! Now i get other errors. |
Posting your code and errors will assist us in helping you.
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Tue Apr 21, 2009 12:16 pm Post subject: |
|
|
| Zerith wrote: | | what do you mean isn't overloadable? everything is overloadable. |
Not everything. Here is a list.
|
|
| Back to top |
|
 |
pkedpker Master Cheater
Reputation: 1
Joined: 11 Oct 2006 Posts: 412
|
Posted: Tue Apr 21, 2009 12:28 pm Post subject: |
|
|
personally I hate C++ because of the overloading its making programming not what it should be.. thats why C is the best language to program in my opinion.
Anyways he is a example of me overloading the () operator
| Code: |
struct Stride
{
int stride;
int NumVertices;
int primCount;
//int startIndex;
bool operator()(Stride& strStart, strStride& End)
{
return strStart.stride < strEnd.stride;
}
};
|
vector<Stride> strides;
now when you call Stride() in the sort method which uses vectors it will sort it in increasing order because of the < check
sort(strides.begin(), strides.end(), Stride());
_________________
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Wed Apr 22, 2009 2:09 am Post subject: |
|
|
| pkedpker wrote: | | Code: | struct Stride
{
...
} |
| Structs are not allowed to have member functions, only classes. C++ might allow member functions in structs, but I'm not sure, just use classes and the case is solved.
| pkedpker wrote: | | now when you call Stride() in the sort method which uses vectors it will sort it in increasing order because of the < check | Make sure you don't get confused between your overloaded operator and the constructor :) You should be doing
|
|
| Back to top |
|
 |
|