Ilya
I assume because of Base *a; So in which cases would function overloading work without using a virtual function ?
When you use an object reference as a reference to the base class, and not to the derived one Just like in your situation Base* ptr = new Derived();
Tazin
#include<iostream> #include<string> using namespace std; void input(string a, string b){ cout<<"Enter your username "<<endl; cin>>a; cout<<"Enter your password "<<endl; cin>>b; } int main(){ string uname, pass; input(uname, pass); //int i=0; for(int i=0; i<=3; i++) { if (uname=="Yakushi" && pass=="ABCK") { cout<<"login successful "; break; } else cout<<"Wrong username or password. Try again."<<endl; input(uname,pass); } cout<<"Bye bye"; return 0; }
Tazin
Can anyone see what's wrong here ?
\Device\NUL
Can anyone see what's wrong here ?
Have you learn reference ?
Tazin
whatever I input it shows wrong username
\Device\NUL
whatever I input it shows wrong username
Because the input is go to local variable, not outside function
นะวู
For reading input
Input of the total number that we need?
\Device\NUL
Umm sorry I didn't get it
The input goes to a and b variable which is only exist in input() function
\Device\NUL
It doesn't refer to uname and pass variable outside the function
Tazin
Ohh
Tazin
So should I just remove function and take input manually?
Tazin
Or there is another way to use function here
\Device\NUL
Or there is another way to use function here
Yes, you could try type reference
\Device\NUL
void input(string& a, string& b);
mito
void input(string& a, string& b);
what's the difference between void input(string& a, string& b); and void input(string *a, string *b); ?
\Device\NUL
Deepak Chaurasia
\Device\NUL
Similar to what std::cin do, it use type-reference
\Device\NUL
Which is why std::cin does not require the reference of the input but scanf require it
Deepak Chaurasia
Here you guys are talking about call be refrence or any other topic?
\Device\NUL
With pointers void func(int *a, int *b) func(&ref, &ano_ref) With reference void func(int &a, int &b) func(ref, ano_ref)
\Device\NUL
Afaik, it's only aliases
Deepak Chaurasia
What is ref and ano_ref
Deepak Chaurasia
Sorry , but i am beginner
\Device\NUL
What is ref and ano_ref
some variables outside func function
mito
I use the pass by pointers all the time.
\Device\NUL
is there any difference between those two in this case ?
Nope Edit: reference can't be nullptr
\Device\NUL
but reference is commonly used with object
mito
but reference is commonly used with object
why are they used with objects commonly ?
\Device\NUL
https://isocpp.org/wiki/faq/references
\Device\NUL
https://isocpp.org/wiki/faq/references#refs-vs-ptrs
Ramil
any good resources on how to code C style C++? Also like to know what are the costs of doing so in a real-life production work
Anatolii
Hi guys! I have a program in C which checks number for repeated digits. It's done by using boolean array and the reason why I'm asking is that I can't completely understand it. To be exact, I'm not sure how does the if statement work on the line 16. I have my code on Hastebin as it's said in the rules. Here's the link https://hastebin.com/tojayeyaca.cpp Thank you in advance!
Asker
Hi everyone I am begginer Please help me for finding problem there #include<iostream> #include<cmath> using namespace std; int main(){ int n; cin>>n; if (10<=n<=99) cout<<pow((n/10+(n-n/10*10),2)); }
Asker
Thanks
klimi
Not used curly bracket after if
but that doesn't fix anything, does it
klimi
the problem is the pow call which doesn't take int as first argument
klimi
ah nah, you just messed up the )
Anonymous
but that doesn't fix anything, does it
C++ solve sequentially that's why it not consider the condition
klimi
pow takes 2 parameters, you have only 1
Anonymous
Anonymous
klimi
I think it's correct we can check it too
yep, it will automatically convert it
klimi
he has first (n/10+(n-n/10*10),2) and there is no second
Anonymous
,2 is the second one
klimi
no
klimi
that would have to be cout<<pow((n/10+(n-n/10*10),2),2);
Anonymous
What's the syntax for pow
klimi
alright, i'll look into the specification
klimi
nope... it seems it takes only float/double as first argument and int/float/double as the second
Anonymous
that would have to be cout<<pow((n/10+(n-n/10*10),2),2);
I think it's wrong may be I miss something becoz i have never seen two commas in pow
klimi
I think it's wrong may be I miss something becoz i have never seen two commas in pow
there is just one... the first argument doesn't make sense (because of the sequence operator) but there is no second argument
klimi
Is their any specific error
it doesn't compile due to test.cpp: In function ‘int main()’: test.cpp:9:10: error: no matching function for call to ‘pow(double)’ 9 | cout<<pow(static_cast<double>(n/10+(n-n/10*10),2)); because it has only one parameter
Asker
Thanks
Anonymous
Thanks dude
Asker
Is their any specific error
No thanks program is working now
Anonymous
Hi guys! I have a program in C which checks number for repeated digits. It's done by using boolean array and the reason why I'm asking is that I can't completely understand it. To be exact, I'm not sure how does the if statement work on the line 16. I have my code on Hastebin as it's said in the rules. Here's the link https://hastebin.com/tojayeyaca.cpp Thank you in advance!
The while loop before the if condition would end only if n becomes 0 or if it breaks out early. It will break out early only if a repeated digit is present and in that case n will still be greater than 0 when the code breaks out of the while loop. If there is no repeated digit then the while loop will exit normally when n becomes 0 due to repeated division by 10. The if condition just checks whether the loop ended normally or prematurely.
Olivia
#include<iostream> #include<vector> using namespace std; int main(){ vector<int> v1; for(int i=1; i<5; i++) v1.push_back(i); cout<<v1.size()<<endl; cout<<v1.capacity()<<endl; v1.resize(7); cout<<v1.size(); v1.shrink_to_fit(); for(auto it=v1.begin(); it!=v1.end(); i++) cout<<*it; return 0; }
Olivia
Why it shows error in data type
Konstantin
Can u help mine problem
#include <vector> mb?
Olivia
Sorry but i cant understand
Konstantin
#include <iostream> #include <vector> using namespace std; int main(){ vector<int> v1; for(int i=1; i<5; i++) v1.push_back(i); cout<<v1.size()<<endl; cout<<v1.capacity()<<endl; v1.resize(7); cout<<v1.size(); v1.shrink_to_fit(); for(auto it=v1.begin(); it!=v1.end(); it++) cout<<*it; return 0; }
Konstantin
it works with no datatype errors
Olivia
Nah still not worrking