Thread: incompatible types in assignment of 'char*'

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #9
    Registered User
    Join Date
    Aug 2019
    Location
    inside a singularity
    Posts
    308
    In general, your Class Methods shouldn't be doing interactive I/O. By interactive, @laserlight means you shouldn't be having things like "Enter Lucy's age: " in your method that does I/O. It takes a lot to take understand the "why" because you are indeed learning one of the hardest languages out there for beginners. You'll gradually understand with time the "why" when you start reading about data abstraction etc. For now, you needn't worry about it and should just care about getting things to work and be able to understand them.
    Make your I/O methods un-interactive. Do the interaction handling separately. Also, you'd probably want the Dog class for different dogs too and not just Lucy. The tutorial explains very well on how to do just that. Also, if seeing things like const written everywhere makes it confusing, you can probably ignore that for now. It's just present so that your methods are valid for const objects too.

    Your code should be more like:

    Code:
    void SetAge ()
    {
          cin >> Age; // You actually need to check here if the user entered a number and not characters but don't worry about that for now
    }
    
    int GetAge () const
    {
         return Age;
    }
    And your interaction should be more like:

    Code:
         cout << "Enter " << dog.GetName () << " 's age: "; dog.SetAge ();
         // Assuming "dog" is an instance/object of your Dog class and GetName has been properly defined the way it should be and assuming the name of the dog has been entered already before filling in the age
    Last edited by Zeus_; 11-21-2019 at 11:29 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-01-2015, 07:13 AM
  2. incompatible types in assignment
    By tetartos in forum C Programming
    Replies: 9
    Last Post: 11-27-2011, 09:39 AM
  3. incompatible types in assignment
    By Adam Rinkleff in forum C Programming
    Replies: 2
    Last Post: 07-13-2011, 01:10 AM
  4. Incompatible types in assignment.
    By killpoppop in forum C Programming
    Replies: 36
    Last Post: 12-22-2008, 12:08 PM
  5. incompatible types in assignment
    By vapanchamukhi in forum C Programming
    Replies: 6
    Last Post: 09-19-2008, 07:45 AM

Tags for this Thread