structs and STL stack

  • Thread starter Christian Christmann
  • Start date
C

Christian Christmann

Hi,

I'd like to store structs on an STL stack.

Here is a piece of my code:

#inclue <stack>
...

struct storeInfo {
int a;
} structInfo;

stack< storeInfo > itStack;
...


When compiling with gcc 3.3.2, I get the error
message:
error: template-argument `areg_action(burm_state*,
>)::storeInfo' uses local type `areg_action(burm_state*,
>)::storeInfo'
error: template argument 2 is invalid
error: ISO C++ forbids declaration of `itStack' with no type

What is wrong?
Thank you.

Chris
 
G

Gavin Deane

Christian said:
Hi,

I'd like to store structs on an STL stack.

Here is a piece of my code:

#inclue <stack>
...

struct storeInfo {
int a;
} structInfo;

stack< storeInfo > itStack;
...


When compiling with gcc 3.3.2, I get the error
message:
error: template-argument `areg_action(burm_state*,


error: template argument 2 is invalid
error: ISO C++ forbids declaration of `itStack' with no type

What is wrong?

Possibly part of what is wrong is that you aren't posting minimal
compileable code copied and pasted directly from your code editor into
your message, thereby risking obfuscating your question and making it
harder for people to help you.
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8

Comeau online has no problem with the short program below. Can you
compile it?

#include <stack>

struct storeInfo
{
int a;
};

int main()
{
std::stack<storeInfo> itStack;
}

Gavin Deane
 
C

Christian Christmann

Comeau online has no problem with the short program below. Can you compile
it?

#include <stack>

struct storeInfo
{
int a;
};

int main()
{
std::stack<storeInfo> itStack;
}
}

Yes, your code works fine.

But why can I not compile it when I move the struct into the main
function?

like:

#include <stack>
int main()
{

struct storeInfo
{
int a;
};

std::stack<storeInfo> itStack;
}
 
T

TB

Christian Christmann skrev:
Yes, your code works fine.

But why can I not compile it when I move the struct into the main
function?

like:

#include <stack>
int main()
{

struct storeInfo
{
int a;
};

std::stack<storeInfo> itStack;
}

You are not allowed to use local types (no linkage) as template
arguments. Only types with external linkage are allowed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top