• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

C++ Scope of template

Status
Not open for further replies.

Digital

Learning C++
Joined
Jul 15, 2018
Messages
57
Solutions
1
Reaction score
12
So I am learning about C++ templates and I am using them to figure out the sources. Right now I only know how to use them for functions.

This is my template and the example code.
C++:
#include <iostream>

template<typename T>
void p(std::string s, T t){
    std::cout << s << " " << t << std::endl;
};

int main() {
    p("this is a float", 1.5);
    p("this is an integer", 24);
    p("this is a character", 'G');
    p("this is a string", "a string");
  
}
and this is how it works
C++:
this is a float 1.5
this is an integer 24
this is a character G
this is a string a string

When applied to the sources what would be the scope of a template if it were not defined inside of a class?
 
you will be able to use that function in every file that includes that header/src where you defined it
 
Status
Not open for further replies.
Back
Top