Thread: Find the problem!

  1. #1
    Registered User
    Join Date
    Feb 2019
    Posts
    11

    Find the problem!

    Code:
    [ Copy Object ]
    1. Use String Class (Remove unnecessary member functions)
    
    
    2. Design an object class.
    
    
       - Memory area where the object's
       - Object serial number (static int m_nNum)
       - Life value (m_nLife)
       - Display method (name, serial number, life value)
    
    
    3. Create an object that is circular to the object.
       - CObject ObjectOrg ("hero", 100);
       - Auto-set name ("hero1") value and serial number to 1.
    
    
    4. Create automatic copying of created objects.
       - CObject Object2 (ObjectOrg);
       - CObject Object3 (ObjectOrg);
    
    
     ObjectOrg is basically complete and doesn't have to complete the rest." (Probably)
    
    
     5. Create copy, but increase name and serial number
       - "Hero 2" for Object2
       - Increase serial numbers
    
    
    6. Decrease the serial number when it expires.
    To reduce static variables 
    (The character-specific number exists.) 
    (The death of Hero 2 does not make Hero 1.)
    
    
    7. Outputs the generation and extinction process using the out.
    
    
    This is an example that I have to complete now, and I've made class number two. I'd like you to see if there's anything weird about it.

  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    11
    Code:
    #include <iostream>
    using namespace std;
    
    
    class CObject
    {
    public:
    	char *_name;//name
    	static int m_nNum;//consecutive numbers
    	int m_nLife;//life
    
    
    private:
    	void objmem(char* name, int life)
        {
            _name = name;
            m_nLife = life;
        }
    }; 
    
    
    void main()
    {
    	CObject ObjectOrg;
        ObjectOrg.objmem("hero", 100);	
    }

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    3,748
    Lookup the meaning of public and private in C++.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  4. #4
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    703
    By the way, main returns int, not void.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array problem. Can you find the problem with this?
    By Aitra in forum C Programming
    Replies: 21
    Last Post: 01-03-2013, 10:33 AM
  2. Can't seem to find the problem, help.
    By JoeyJoe in forum C Programming
    Replies: 8
    Last Post: 03-04-2011, 02:03 PM
  3. help me to find the problem
    By behzad_shabani in forum C Programming
    Replies: 3
    Last Post: 06-12-2008, 01:17 AM
  4. pls help i cant find the problem :(((
    By condorx in forum C Programming
    Replies: 3
    Last Post: 11-07-2002, 09:05 AM
  5. Can't find problem
    By b-ref in forum C Programming
    Replies: 2
    Last Post: 12-06-2001, 05:39 AM

Tags for this Thread