If anyone's max function doesn't return values the same way it does in the video, it may be because you've typed "using namespace std;" at the top of your file. I recommend you to remove it because there is a function that is called max() in that std library and C++ thinks it needs to choose this function rather than yours.
This video has reduced ambiguity about fiction template which was increased by other video tutorials . However, class templates remains a mystery to me. I just can't comprehend it thoroughly. Can you bro make an extensive video tutorial on Class templates? Are they really useful?
When attempting template auto max(T x, U y){} I get an error saying ‘auto’ not allowed in function return type, even though I should have the most updated C++ extension on VS Code. Any ideas?
my assignment: // -----------------------------------------project name: multiple function template // write a function once, then it's compatible with different data types = that's function template. With auto keyword the function return type is automatically detected or deduced by the compiler #include template auto max(T x, U y) { return (x > y) ? x : y; } int main() { std::cout
Not optimal for big functions. While we use auto, the function becomes dynamic. Also, it comes at the cost of code readability and makes it harder to debug. :)
#include
template
T max(T x, T y){
return (x > y) ? x : y;
}
int main()
{
std::cout
l just learned about this channel and it's AMAZING! Really nice job, big like for the explaination and for that huge series!
If anyone's max function doesn't return values the same way it does in the video, it may be because you've typed "using namespace std;" at the top of your file. I recommend you to remove it because there is a function that is called max() in that std library and C++ thinks it needs to choose this function rather than yours.
It was useful. nice and simple. Thanks for sharing.
This video has reduced ambiguity about fiction template which was increased by other video tutorials .
However, class templates remains a mystery to me. I just can't comprehend it thoroughly. Can you bro make an extensive video tutorial on Class templates? Are they really useful?
When attempting
template
auto max(T x, U y){}
I get an error saying ‘auto’ not allowed in function return type, even though I should have the most updated C++ extension on VS Code. Any ideas?
Try returning this: return (x > y) ? x : y;
Awesome video again. So there is no reason at all to use an overloaded function anymore?
Bro when I add namespace std, the templates don't work, do you know why?
I'm not sure if you had fixed it, but you can write " cout
So is this java's generic equivalent in c++? I know it is other way but in simple saying.
Is the template only used above the main function?
why was i kept away from this video
my assignment:
// -----------------------------------------project name: multiple function template
// write a function once, then it's compatible with different data types = that's function template. With auto keyword the function return type is automatically detected or deduced by the compiler
#include
template
auto max(T x, U y)
{
return (x > y) ? x : y;
}
int main()
{
std::cout
You could use auto instead
copied your code with the auto keyword word for word and got an error?
Why not always use auto?
Not optimal for big functions. While we use auto, the function becomes dynamic. Also, it comes at the cost of code readability and makes it harder to debug. :)
this is very useful
why don't we just turn them all auto
#include
auto max(auto x , auto y){
return (x>y) ? x : y ;
}
int main () {
std::cout
The auto keyword is not allowed as a parameter type in C++ function declarations.
template
🤯
#include
#include // For sqrt() function
template
float distance(T v1, U v2, V v3){
return sqrt(v1 * v1 + v2 * v2 + v3 * v3);
}
int main(void){
// Example Usage
std::cout
#include
template
auto min(T x, U y){
return (x < y) ? x : y;
}
int main(){
std:cout
ahh Template == Generics
auto is like var
#include
template
auto min(T x, U y){
return (x < y) ? x : y;
}
int main()
{
std::cout
#include
template
auto min(T x, U y){
return (x < y) ? x : y;
}
int main () {
std::cout
#include
template
auto max(T x, U y){
return (x > y) ? x : y;
}
int main()
{
std::cout
auto min(T x, U y){
return(x < y) ? x : y;
}