Where to place STL / template code c++? -


hi have quick question. part of homework i've been asked write own template vector class (most of code there needs expanded upon). while understand how works , have no idea put code or reference have never seen in context within program.

do create new cpp file information in it, or add in above main method? if create new file (either cpp or h) how reference it, #include normal?

this might seem simple i've tried creating new .h file , including in main program scope definition errors.

most compilers require put template code in header file, rather source. due way template expansion works. include header in whichever files need use vector class.

some things watch out when creating header:

  1. prevent multiple inclusion. if compiler supports #pragma once can put @ top, otherwise use #ifndef my_header_h ....... pattern.
  2. don't forget put semi-colon on end of class!!!!
  3. never put using namespace whatever; in outer scope of header (it's okay use within block scope such namespace { ... } or function).
  4. be careful of name conflicts std::vector if calling class vector - make sure nobody has imported std namespace prior including header.

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -