Stoopid me
-
I just produced this Gem:
template struct Expectation{
T expected;
Expectation(T e)
: expected(e){}
bool Expect(const T &other){
return (other == expected);
}
};Which shall be used as
foo firstFoo(1);
Expectation myExpectation();
foo anotherFoo(1);
if(myExpectation.Expect(anotherFoo)){
//bar
}After I got a coffee (proud of the genius work I did) I returned to my desk an all of sudden I realised that I just could've written
foo firstFoo(1);
foo anotherFoo(1);
if(firstFoo == anotherFoo){
//bar
}One hour left, it's definately time for me to get outta here :doh:
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
-
I just produced this Gem:
template struct Expectation{
T expected;
Expectation(T e)
: expected(e){}
bool Expect(const T &other){
return (other == expected);
}
};Which shall be used as
foo firstFoo(1);
Expectation myExpectation();
foo anotherFoo(1);
if(myExpectation.Expect(anotherFoo)){
//bar
}After I got a coffee (proud of the genius work I did) I returned to my desk an all of sudden I realised that I just could've written
foo firstFoo(1);
foo anotherFoo(1);
if(firstFoo == anotherFoo){
//bar
}One hour left, it's definately time for me to get outta here :doh:
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
which in addition should return false as long as its a reference type and you didn't overwrite the Equals Operator ;)
-
which in addition should return false as long as its a reference type and you didn't overwrite the Equals Operator ;)
Nicholas Marty wrote:
you didn't overwrite the Equals Operator
I overwrote it. Well, better: I had to implement it since QObject (the base class for objects in the Qt framework) has not implemented it (means not implementing the equals operator would've led to a compiler error, anyways). Edit: QObject has also a private copy constructor, means that you have to implement a copy constructor yourself before doing something like
foo myFoo = GetFoo(); //Assuming GetFoo returns a foo type
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
-
Nicholas Marty wrote:
you didn't overwrite the Equals Operator
I overwrote it. Well, better: I had to implement it since QObject (the base class for objects in the Qt framework) has not implemented it (means not implementing the equals operator would've led to a compiler error, anyways). Edit: QObject has also a private copy constructor, means that you have to implement a copy constructor yourself before doing something like
foo myFoo = GetFoo(); //Assuming GetFoo returns a foo type
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
Assuming this is C#, shouldn't the example be like this?
foo myFoo = new foo(GetFoo())
At the moment you only assign the reference, not requiring a copy constructor.
The good thing about pessimism is, that you are always either right or pleasently surprised.
-
Assuming this is C#, shouldn't the example be like this?
foo myFoo = new foo(GetFoo())
At the moment you only assign the reference, not requiring a copy constructor.
The good thing about pessimism is, that you are always either right or pleasently surprised.
Freak30 wrote:
Assuming this is C#
It is not. It is C++.
Freak30 wrote:
At the moment you only assign the reference, not requiring a copy constructor.
The foo class is inherited from QObject, where an assignment automatically invokes the copy constructor (despite you are working with pointers, off course).
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
-
Freak30 wrote:
Assuming this is C#
It is not. It is C++.
Freak30 wrote:
At the moment you only assign the reference, not requiring a copy constructor.
The foo class is inherited from QObject, where an assignment automatically invokes the copy constructor (despite you are working with pointers, off course).
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
Don't all C++ object assignments invoke the copy constructor?
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p) "Given the chance I'd rather work smart than work hard." - PHS241 "'Sophisticated platform' typically means 'I have no idea how it works.'"
-
Don't all C++ object assignments invoke the copy constructor?
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p) "Given the chance I'd rather work smart than work hard." - PHS241 "'Sophisticated platform' typically means 'I have no idea how it works.'"
I suppose they do - Except for some special cases (private copy constructor, as seen in the QObject class).
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
-
Assuming this is C#, shouldn't the example be like this?
foo myFoo = new foo(GetFoo())
At the moment you only assign the reference, not requiring a copy constructor.
The good thing about pessimism is, that you are always either right or pleasently surprised.
Wrong asssumption, the
template <class T> struct Expectation
bit gives it away.
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.
-
Assuming this is C#, shouldn't the example be like this?
foo myFoo = new foo(GetFoo())
At the moment you only assign the reference, not requiring a copy constructor.
The good thing about pessimism is, that you are always either right or pleasently surprised.
Why on earth would you assume it is C#. Does "
template <class T> struct Expectation ...
" make any sense in C#?"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.