Help getting this to work xd
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Help getting this to work xd

  1. #1
    Join Date
    Mar 2017
    Posts
    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 07:26 AM. Reason: Added code tags

  2. #2
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,451

    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 07:39 AM.
    All advice is offered in good faith only. 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/

    C, C++ Compiler: Microsoft VS2017.2

  3. #3
    Join Date
    Mar 2017
    Posts
    1

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)