Dima
You better to use “using” it’s much cleaner
Harshit
It was just a question
Harshit
For my assignment
Dima
Read the rules
Nils
You better to use “using” it’s much cleaner
I know but I am writing a library where "using" can cause trouble
Dima
That evil looking syntax I don’t remember lol
Liam
Nils
looks strange. what's your original issue?
Well I have many functions that need a whole lot of arguments and every of them need the same arguments
Harshit
You guys are just unbearable...
Anonymous
like: typedef std::function<int(char *argv[])> mode; mode { ... }
int foo(const char *bar); typedef decltype(foo())* mode;
Liam
Well I have many functions that need a whole lot of arguments and every of them need the same arguments
so every function in this cluster has the same argument list and the same return type?
Liam
yep
using macro magic can solve.
Nils
int foo(const char *bar); typedef decltype(foo())* mode;
I don't really understand this piece of code tbh
Nils
It does not look like it does what I want it to
Anonymous
I don't really understand this piece of code tbh
typedef int (*)(const char *) mode;
Nils
using macro magic can solve.
Okay, thx... I'll look that up
Anonymous
typedef int (*)(const char *) mode;
i just used decltype to deduce the function type
Liam
I don't really understand this piece of code tbh
#define magic(func) return_type func(argument_list) something like this?
Liam
well, he is not seeking a way to get function type.
Nils
typedef int (*)(char *argv[]) mode;
Okay, I'll try that too
Anonymous
Okay, I'll try that too
no. that is not what you want
Liam
#define magic(func) return_type func(argument_list) something like this?
and the usage magic(new_func_name) { // body of the func. }
Liam
thx!
: )
Anonymous
hi i am new in programming site can you recommend any books for me.i am a beginner. WARN ME IF MY REQUEST IS GONE AGAINST GROUP RULES>
Dima
we’re planning to prohibit site/books requests because too many of questions
Liam
lol
Liam
cs50x is good
Anonymous
we’re planning to prohibit site/books requests because too many of questions
i think some of the rose commands should be added to the pinned message
Dima
yeah
Liam
making Rose be able to response the book list to newbies in private message sounds better
Nils
and the usage magic(new_func_name) { // body of the func. }
Having trouble with that… https://hastebin.com/xuqoquteyu.cpp In line 8: expected expression in line 14: expected ';' after top level declarator
Anonymous
Liam
Rose, you're an adult bot now, you shall know how to solve these kind of question now.
Liam
lol
Anonymous
Probably I am doing something very wrong
#define is a preprocessor macro. it does text substitution
Nils
#define is a preprocessor macro. it does text substitution
Okay, I changed it. However I am still getting these errors
Nils
it's #define mode_tmpl(func) int func(char *argv[], unsigned long numposts, std::vector<std::string> postsmap_numname, std::vector<std::string> postsmap_nummeta,std::vector<std::string> postsmap_numurl, std::vector<std::string> postsmap_numdesc,std::vector<std::vector<std::string>> postsmap_numfileurls, std::vector<std::vector<std::string>> postsmap_numfilenames) now
Nils
Errors:
Nils
https://hastebin.com/uyuniqapuq.cpp
Liam
macro with multiple lines requires \ at end of each lines
Liam
or /
Liam
not so sure
Anonymous
Anonymous
\ followed by newline character in source file causes both characters to be deleted, joining the line. it's not specific to macros
Liam
It's just on eline
well, how did you use it? #include <iostream> #define func_temp(func) int func(int a, \ int b) func_temp(func) { return a + b; } int main() { std::cout << func(1, 2) << std::endl; return 0; } the above passes the compiler and works well.
Nils
Solved!
Anonymous
https://hastebin.com/onehurageb.cpp
#define does text substitution. where do you use mode_tmpl?
Nils
I used mode instead of mode_tmpl
Liam
😂
Tushar Goel
Sorry
Tushar Goel
Please remove warn
Tushar Goel
actually I forgot
Tushar Goel
#include <stdio.h> #include <string.h> int main() { int i = 4; double d = 4.0; char s[] = "HackerRank "; int a; double b; scanf("%d",&a); scanf("%lf",&b); char c[20]; gets(c); printf("%d\n",a+i); printf("%0.1lf\n",b+d); strcat(s,c); puts(s); return 0; }
Tushar Goel
The compiler doesnt compile gets statement in my program
Tushar Goel
whats wrong?
Mar!o
What exactly the message?
Tushar Goel
Nothing
Anonymous
Nothing
are you giving input ?
Nils
What is the fastest way to get a key by value in map?
Tushar Goel
are you giving input ?
Thats the issue. Comliler doest ask for the input
Mar!o
?? Which compiler? GCC? MSVC?
Anonymous
Thats the issue. Comliler doest ask for the input
it does work for me though are you using an online compiler ? if yes, try to write your input in a textbox.
Mar!o
Clang, MingW, Tcc?
Tushar Goel
and also hackerRank