Class Basics

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • perto1
    New Member
    • Apr 2022
    • 1

    #1

    Class Basics

    Hi, I am a first semester student, learning the OOPs basics. I need help for a program:

    Code:
    class Message{
    public:
    	void input();
    	int output();
    private:
    	long token_number;// next token to be given to client
    
    };
    
    void Message::input()
    {
    	token_number = 1;
    }
    
    int Message::output()
    {
    	return token_number;
    }
    I dont know the right way to call these elements in the main()
    Code:
    int main(){
    Message obj;
    
    std::cout<< out_buffer<<obj.output()<<std::endl;//write the token number in the buffer
    std::cout<<"Response received"<<++obj.input();//To update the input value and display
    }
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    Code:
    int main(){
    Message obj;
     
    std::cout<< out_buffer<<obj.output()<<std::endl;//write the token number in the buffer
    std::cout<<"Response received"<<++obj.input();//To update the input value and display
    }
    What are you trying to do?

    You might be looking for
    Code:
    int main() {
      Message obj;
      obj.input();
      std::cout << obj.output();
      return 0;
    }
    • A member function can be used to update the private data members.
    • A constructor is used to initialize the object.

    Comment

    Working...