Created
February 6, 2014 03:32
-
-
Save darchons/8838009 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class Impl> | |
class Base { | |
public: | |
static int DoWork() { | |
return Impl::DoSubWork(); | |
} | |
}; | |
class WorkA : public Base<WorkA> { | |
public: | |
static int DoSubWork() { | |
return 1; | |
} | |
}; | |
class WorkB : public Base<WorkB> { | |
public: | |
static int DoSubWork() { | |
return 2; | |
} | |
}; | |
int main() { | |
WorkA::DoWork(); | |
WorkB::DoWork(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class Work> | |
int DoWork() { | |
return Work::DoSubWork(); | |
} | |
class WorkA { | |
public: | |
static int DoSubWork() { | |
return 1; | |
} | |
}; | |
class WorkB { | |
public: | |
static int DoSubWork() { | |
return 2; | |
} | |
}; | |
int main() { | |
DoWork<WorkA>(); | |
DoWork<WorkB>(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Base { | |
public: | |
virtual int DoSubWork() = 0; | |
int DoWork() { | |
return DoSubWork(); | |
} | |
}; | |
class WorkA : public Base { | |
public: | |
virtual int DoSubWork() { | |
return 1; | |
} | |
}; | |
class WorkB : public Base { | |
public: | |
virtual int DoSubWork() { | |
return 2; | |
} | |
}; | |
int main() { | |
WorkA().DoWork(); | |
WorkB().DoWork(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment