C ++ Class Prototype

2

Hello, I have a problem:

include <iostream>

using namespace

class varios;

int main()
{
   cuerpo.hola();
   cin.get();
   return 0;
}

class varios
{
   public:
   void hola();
}cuerpo;

void class::hola()
{
   cout<<"Este es un ejemplo";
}

I am declaring a prototype class, but I do not know how to declare the object to be recognized by the main

    
asked by Malthael 03.01.2017 в 23:20
source

1 answer

3

Do not define variables at the end of the class declaration.

Simply use the name of the class as if it were a standard type:

#include <iostream>

class varios
{
   public:
        void hola();
};

void varios::hola()
{
   std::cout<<"Este es un ejemplo";
}

int main()
{
   // Defines una variable de tipo varios
   varios cuerpo;
   cuerpo.hola();

   return 0;
}
    
answered by 04.01.2017 / 00:34
source