Iso c++ forbids declaration of "variable name" with no type

Sep 15, 2011 at 1:25pm
Hey guys, i have been learning c++ for about some time and never had any problems as i could search them and find them, but this time i dont know what i am doing wrong :/
This is what i have coded so far:
#include <iostream>
#include <string.h>

using namespace std;
int main()
{
    int opcion,contrasena;
    cout << "Encripción de contraseña" << endl;
    cout<<"Para Mostrar la contraseña ingrese 1"<<endl;
    cout<<"Para Encriptar una contraseña ingrese 2"<<endl;
    cin>>opcion;

    if (opcion == 1){

//Clase que encripta la contraseña
class encriptar_contrasena
{
    //Definicion de variables
    string contrasena_sinencriptar;
    float continuar, primera_ejecucion;
    public:
    //Valores de variables

    continuar = 1;
    primera_ejecucion = 1;

    //Funciones

    if (primera_ejecucion == 1)
    {
        cout<<"Ingrese la contraseña a encriptar"<<endl;
        cout<<"La contraseña contiene "<<str.size()<< "Caracteres"<<endl;
        cin >> contrasena_sinencriptar;
        cout<<"Encriptando contraseña ...."<<endl;


    }
};
}
}

It gives me the error Iso c++ forbids declaration of "continuar" with no type, even when i have seted it to be a float.
Help would be amaizing, thanks you guys!
Sep 15, 2011 at 1:32pm
You just dumped that code into the class declaration. It needs to be inside a function.
Sep 15, 2011 at 1:33pm
1) Try to use english variable and method names. It's really hard for others to read your code if they don't understand them.

2) use [code ] [ /code] tags, not [ output ] for code.

3) Your class declaration is quite peculiar. You seem to have an if statement right in the middle of it.
Sep 15, 2011 at 1:35pm
There is something very wrong with your understanding of classes. A class cannot contain any executable code (as opposed to declarations) outside of its methods (or constructor or destructor or static functions) (I might be slightly generalizing here).
I suggest reading a tutorial on classes.
Topic archived. No new replies allowed.