Templates and Namespaces
Visual Computing in OpenCV: Seminar 1 Hannes Ovrén
Department of Electrical Engineering Computer Vision Laboratory Linköping University August 23, 2012
Templates and Namespaces Visual Computing in OpenCV: Seminar 1 - - PowerPoint PPT Presentation
Templates and Namespaces Visual Computing in OpenCV: Seminar 1 Hannes Ovrn Department of Electrical Engineering Computer Vision Laboratory Linkping University August 23, 2012 Outline 1. Namespaces Introduction Namespaces in your
Department of Electrical Engineering Computer Vision Laboratory Linköping University August 23, 2012
2
3
4
5
6
7
namespace foo { void TopLevelFunction(int x); }
#include <foo/foo.h> #include <foo/bar/bar.h> int main() { int x = 5, y = 10; foo::TopLevelFunction(x); foo::bar::SubPackageFunction(x, y); }
namespace foo { namespace bar { void SubPackageFunction(int x, int y); } void AnotherTopLevelFunction(int x); }
8
9
10
11
12
13
// Generic template implementation template <typename T> T GetMax(T a, T b) { return a >= b ? a : b; } // For chars, ignore case template <> // empty type char GetMax<char>(char a, char b) // but note the <char> here! { // Convert to lowercase char a_low = tolower(a); char b_low = tolower(b); return a_low >= b_low ? a : b; } // Examples char a = ’a’; // value: 97 char b = ’B’; // value: 66 char c; c = a >= b ? a : b; // returns ’a’ (mimic generic GetMax) c = GetMax<char>(a, b); // returns ’B’
14
15