Thread: function

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

    Unhappy function

    Is there a problem with class CObject now ?
    Why is there an error in(char *name, int m_nLife) ?
    Why does the word "I need a discriminator" come out ?
    Code:
    #include <iostream>
    using namespace std;
    
    class S {
    public:
      char *_name;                  //name
      static int m_nNum;            //consecutive numbers
      int m_Life = 0;               //life
    
    private:
      class CObject(char *name, int m_nLife)  //circular object    
      {
    
      };
    
      class Displaymethod(char *_name, int objnum, int objnum) {
    
      };
    };
    
    void main()
    {
      CObject ObjectOrg();          //Still under development
    }
    : confused:
    Last edited by Salem; 03-15-2019 at 07:03 AM. Reason: removed crayola

  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    11
    I'm sorry. I know the problem.
    If I ask you a question again, can I put a class in the class?

  3. #3
    Registered User
    Join Date
    Feb 2019
    Posts
    11
    If you created a class in a class
    How do you create a class such as CObject ObjectOrg() using the class in the class?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    A class in a class.
    Code:
    class S {
    public:
      char *_name;                  //name - use std::string for everything
      int m_nNum;            //consecutive numbers  // Why static?
      int m_Life;               //life
    
    private:
      class CObject {
        private:
          int foo;
        public:
          CObject() {
              foo = 0;
          }
      };
      CObject aThing;
    };
    
    int main ( ) {
        S   myFoo;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Nested classes are legal in C++, but why do you want a nested class? It looks like you're trying to define a member function.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 10-02-2018, 09:52 AM
  2. Function Prototype, Function Call, and Function definition
    By dmcarpenter in forum C Programming
    Replies: 9
    Last Post: 04-09-2013, 03:29 AM
  3. Replies: 13
    Last Post: 03-20-2012, 08:29 AM
  4. Print function: sending a function.. through a function?
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 11-05-2008, 05:03 PM
  5. Replies: 9
    Last Post: 01-02-2007, 04:22 PM

Tags for this Thread