void foo Download presentation Presentation is loading. Please wait. Published by강성 애
Modified over 5 years ago
1
foo.h #ifndef _FOO #define _FOO template <class T> class foo{
2
foo.cpp #include "foo.h" template <class T>
3
fooImpl.cpp #include "foo.cpp" template foo<int>;
4
goodtestFoo.cpp #include <iostream> using namespace std;
5
badTestFoo.cpp #include <iostream> using namespace std;
6
compile, run goodtestfoo
7
compiling badtestfoo linux3[104] % g++ -o badtestfoo badtestfoo.cpp fooImpl.cpp badtestfoo.cpp: In function `int main()': badtestfoo.cpp:10: no matching function for call to `foo<double>::set(double)'
Similar presentations © 2025 SlidePlayer.com. Inc. Log in
foo.h #ifndef _FOO #define _FOO template <class T> class foo{
Similar presentations
Presentation on theme: "foo.h #ifndef _FOO #define _FOO template <class T> class foo{"— Presentation transcript:
private: T f; public: void setFoo(T val); T getFoo(); }; #endif
void foo<T>::setFoo(T val){ f = val; } T foo<T>::getFoo(){ return f;
#include "fooImpl.cpp" int main(){ foo<int> myFoo; myFoo.setFoo(42); cout << "we got " << myFoo.getFoo() << endl; return 0; }
#include "fooImpl.cpp" int main(){ foo<int> myFoo; myFoo.setFoo(42); cout << "we got " << myFoo.getFoo() << endl; foo<double> anotherFoo; //OOPS! – not instantiated anotherFoo.set(64.5); cout << "we got " << anotherFoo.getFoo() << endl; return 0; }
linux3[106] % g++ -o goodtestfoo goodtestfoo.cpp fooImpl.cpp linux3[107] % goodtestfoo we got 42
Similar presentations
All rights reserved.