-
March 1st, 2017, 06:59 PM
#1
Help getting this to work xd
Code:
#include <iostream>
#include <string>
using namespace std;
class FinestExe{
public:
void setPass(string x) {
string pass;
pass = "finest1";
}
private:
};
class Finest{
public:
void pass() {
string pass;
pass = "finest1";
}
void FinestExecutor() {
cout << "Finest Executor!\n";
}
void Incorrect(){
cout << "Incorrect \n";
}
};
int main()
{
Finest Object;
FinestExe Object2;
if (Object2.setPass == Object.pass) {
Object.FinestExecutor();
} else {
Object.Incorrect();
}
cin.get();
cin.ignore();
return 0;
}
Last edited by 2kaud; March 2nd, 2017 at 08:26 AM.
Reason: Added code tags
-
March 2nd, 2017, 08:24 AM
#2
Re: Help getting this to work xd
When posting code, please use code tags so that the code is readable. Go Advanced, select the formatted code and click '#'.
Code:
void setPass(string x) {
string pass;
pass = "finest1";
}
This has no effect. The variable pass is local to the function setPass() so its value is only available for the duration of setPass(). Once setPass() exits, the variable pass ceases. The same applies for pass().
Do you mean this
Code:
#include <iostream>
#include <string>
using namespace std;
class FinestExe {
public:
void setPass(const string& x) {
pass = x;
}
string getPass() {
return pass;
}
private:
string pass;
};
class Finest {
public:
void setPass() {
passf = "finest1";
}
void FinestExecutor() {
cout << "Finest Executor!\n";
}
void Incorrect() {
cout << "Incorrect \n";
}
string getPass() {
return passf;
}
private:
string passf;
};
int main()
{
Finest Object;
FinestExe Object2;
Object2.setPass("finest1");
Object.setPass();
if (Object2.getPass() == Object.getPass()) {
Object.FinestExecutor();
} else {
Object.Incorrect();
}
cin.get();
cin.ignore();
return 0;
}
Last edited by 2kaud; March 2nd, 2017 at 08:39 AM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
March 7th, 2017, 12:04 AM
#3
Re: Help getting this to work xd
Your code has lot of compilation problem. If you want to run the program then fix the compilation errors first.
If you are using linux then you need to check what your function takes and what it returns when you try to use a function.
If you are using VS or any IDE then you will get the help of the inteli sence to help you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|