Jump to content

Including libraries in header file problem.

- - - - -

  • Please log in to reply
1 reply to this topic

#1
notes

notes

    Learning Programmer

  • Members
  • PipPipPip
  • 48 posts
Hi,

My problem is that I want to create class witch will use stack library. But my compiler seems not to include library... Here is code :
hanoi.h
#ifndef HANOI

#define HANOI


#include <stack>

class hTower {

    private :

        stack<int> A; // Here is error

    public :

        hTower();


};




#endif

hanoi.cpp
#include <stack>

#include <iostream>

#include <cstdlib>

#include "hanoi.h"

using namespace std;

main.cpp
#include <iostream>

#include "hanoi.h"


using namespace std;


int main(int argc, char *argv[])

{

    

    

    return 0;

}


Error :
"In file included from main.cpp,
ISO C++ forbids declaration of 'stack' with no type,
expected ';' before '<' token "

My question is, how to include stack library so that I can declare stack in my class? I've noticed the same problem with vector library...
Using Dev C++.


EDIT :
NVM, seems I had to put std:: before declaration. Problem solved.

Edited by notes, 16 November 2011 - 06:00 AM.
Solved myself

Remebre about KISS & DRY

#2
AKMafia001

AKMafia001

    Programmer

  • Members
  • PipPipPipPip
  • 119 posts
Specify it's scope, it belongs to namespace std.


    std::stack<int> A;


Hope this Helps!

--------------------------------------------------------------

I guess i'm enough late... :)

Edited by AKMafia001, 16 November 2011 - 06:39 AM.
Already solved...

I think i'm able to write a code for printing "Hello, World!". Proud of that!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users