elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Los 10 CVE más críticos (peligrosos) de 2020


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  AYUDA error maldito
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: AYUDA error maldito  (Leído 2,275 veces)
RockAqp

Desconectado Desconectado

Mensajes: 30


Ver Perfil
AYUDA error maldito
« en: 17 Mayo 2010, 01:17 am »

olaz manes weno quiero que me ayuden con este programa no se que esta mal pero me sale identificador no declararo y esta declarado :D hay les dejo el codigo esta en dos partes .h y .cpp
AKI EL PUNTO CPP
Código:
//Programa para probar varias opciones de una Pila

#include "iostream"
#include "myStackLinked.h"
#include "stdio.h"
using namespace std;

void main()
{
    int valor;
   
stackType<int> intStack;
stackType<int> tempStack;
    intStack.initializeStack();
cout<<"Usted ha creado una pila de 5 posiciones";
cout<< endl;
intStack.push(23);
intStack.push(45);
intStack.push(38);

tempStack = intStack;  //copia intStack en copyStack

cout<<"Elementos en la pila tempStack: ";
cout<<endl;
   

while(!tempStack.isEmptyStack())  //print copyStack
{
cout<<tempStack.top()<<" ";
    tempStack.pop();
}

cout<<endl;
cout<< "Ingrese un nuevo elemento para la pila: ";
    cin>>valor;
intStack.push(valor);

cout<< "Ingrese un nuevo elemento para la pila: ";
    cin>>valor;
intStack.push(valor);

// Mostrando la pila
    while(!intStack.isEmptyStack())  //print intStack
{
cout<<intStack.top()<<" ";
    intStack.pop();
}

    cout<<endl;
    cout<< "Ingrese un nuevo elemento para la pila: ";
    cin>>valor;
intStack.push(valor);

    cout<<endl;
cout<< "Ingrese un nuevo elemento para la pila: ";
    cin>>valor;
intStack.push(valor);

cout<<endl;
cout<<"El elemnto en el tope de  intStack es: "<<intStack.top()<<endl;


//cout<<"Ahora el elemnto en el tope de  intStack es: "<<intStack.top()<<endl;
//cout<<tempStack.top()<<" ";

system("pause");

}






AKI EL .H


Código:
// myStackLinked.h; Header file

#ifndef H_StackType
#define H_StackType

#include <iostream>
#include <cassert>

using namespace std;

template <class Type>
struct nodeType
{
Type info;
nodeType<Type> *stackTop;
};

template<class Type>
class stackType
{
public:
    const stackType<Type>& operator=(const stackType<Type>&);

    void initializeStack();
//Function to initialize the stack to an empty state.
//Postcondition: stackTop = 0
void destroyStack();
//Function to remove all the elements from the stack.
//Postcondition: stackTop = 0
    bool isEmptyStack();
//Function to determine whether the stack is empty.
//Postcondition: Returns true if the stack is empty;
//               otherwise, returns false.
    void push(const Type& newItem);
//Function to add newItem to the stack.
//Precondition: The stack exists and is not full.
//Postcondition: The stack is changed and newItem
//               is added to the top of stack.
    Type top();
//Function to return the top element of the stack.
//Precondition: The stack exists and is not empty.
  //Postcondition: If the stack is empty, the program
//               terminates; otherwise, the top element
//               of the stack is returned.
    void pop();
//Function to remove the top element of the stack.
//Precondition: The stack exists and is not empty.
//Postcondition: The stack is changed and the top
//               element is removed from the stack.

    stackType();
//constructor
//Creates an array of the size stackSize to hold the
//stack elements. The default stack size is 100.
//Postcondition: The variable list contains the base
//               address of the array, stackTop = 0, and 
//               maxStackSize = stackSize.
    stackType(const stackType<Type>& otherStack);
//copy constructor
    ~stackType();
//destructor
//Removes all the elements from the stack.
//Postcondition: The array (list) holding the stack
//               elements is deleted.

private:

    nodeType<Type> *link;
    void copyStack(const stackType<Type>& otherStack);
  //Function to make a copy of otherStack.
  //Postcondition: A copy of otherStack is created and
  //               assigned to this stack.
};


template<class Type>
void stackType<Type>::initializeStack()
{
destroyStack();
}

template<class Type>
void stackType<Type>::destroyStack()
{
nodeType<Type> *temp;

while(stackTop != NULL)
{
   temp = stackTop;
   stackTop = stackTop->link;
   delete temp;
}

stackTop = 0;
}
template<class Type>
bool stackType<Type>::isEmptyStack()
{
return (stackTop==0);
}

template<class Type>
void stackType<Type>::push(const Type& newItem)
{
nodeType<Type> *newNode;

newNode = new nodeType<Type>;

assert(newNode != NULL);

newNode->info = newItem;
newNode->stackTop = stackTop;
  stackTop = newNode;
                                                             
}

template<class Type>
Type stackType<Type>::top()
{
assert(stackTop!= 0);
return (stackTop->info);
}

template<class Type>
void stackType<Type>::pop()
{
nodeType<Type> *temp;
if(!isEmptyStack()){
   temp=stackTop;
   stackTop=stackTop->link;     
   delete temp;
}
  else
   cerr<<"Cannot remove from an empty stack."<<endl;
}

template<class Type>
stackType<Type>::stackType()
{
stackTop = 0;
}

template<class Type>
stackType<Type>::~stackType() //destructor
{
   destroyStack();
}

template<class Type>
void stackType<Type>::copyStack(const stackType<Type>& otherStack)
{

   nodeType<Type> *newNode;
   nodeType<Type> *current;

   if(!isEmptyStack())
  destroyList();

   if(otherList.isEmptyStack())
stackTop = NULL;
   else
   {
current = otherList.stackTop;

stackTop = new nodeType<Type>;

  assert(stackTop != NULL);

stackTop->info = current->info;
stackTop->link = NULL;

current = current->link;

while(current != NULL)
{
newNode = new nodeType<Type>;

assert(newNode!= NULL);

newNode->info = current->info;
newNode->link = NULL;   
                                   
current = current->link;
}
}
}


template<class Type>
stackType<Type>::stackType(const stackType<Type>& otherStack)
{
stackTop = NULL;

copyStack(otherStack);
}

template<class Type>
const stackType<Type>& stackType<Type>::operator=
    (const stackType<Type>& otherStack)
{

   if(this != &otherStack)
    copyStack(otherStack);

   return *this;
}

#endif


weno se agradece ...
salu...


En línea

@synthesize
Wiki

Desconectado Desconectado

Mensajes: 640


Another Brick in the Wall


Ver Perfil WWW
Re: AYUDA error maldito
« Respuesta #1 en: 17 Mayo 2010, 01:54 am »

No he leido el code, pero, no debería ser así?

Código
  1.  
  2. #include <iostream.h>
  3. #include "/ruta/myStackLinked.h"
  4. #include <stdio.h>
  5.  
  6.  


En línea

Eternal Idol
Kernel coder
Moderador
***
Desconectado Desconectado

Mensajes: 5.937


Israel nunca torturó niños, ni lo volverá a hacer.


Ver Perfil WWW
Re: AYUDA error maldito
« Respuesta #2 en: 17 Mayo 2010, 09:40 am »

stackTop es un miembro de nodeType y no de stackType, aunque en esta ultima tenes un miembro llamado link que es del tipo nodeType ... fijate que quisiste hacer, usar link->stackTop no es una solucion (en destroyStack o pop por ejemplo).

Lo mas logico para las cabeceras es:

Código
  1. #include <iostream>
  2. #include "myStackLinked.h"
  3. #include <stdio.h>
En línea

La economía nunca ha sido libre: o la controla el Estado en beneficio del Pueblo o lo hacen los grandes consorcios en perjuicio de éste.
Juan Domingo Perón
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
ayuda con el maldito bitlocker
Windows
hardyan2 1 4,809 Último mensaje 16 Diciembre 2010, 09:48 am
por madpitbull_99
nesesito ayuda con mi maldito vecino « 1 2 »
Hacking Wireless
TheInvader22 11 6,150 Último mensaje 28 Diciembre 2011, 19:17 pm
por beholdthe
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines