By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,526 Members | 1,895 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,526 IT Pros & Developers. It's quick & easy.

structs and STL stack

P: n/a
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*,
std::basic_string<char, std::char_traits<char>, std::allocator<char>
)::storeInfo' uses local type `areg_action(burm_state*, std::basic_string<char, std::char_traits<char>, std::allocator<char>)::storeInfo'

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

What is wrong?
Thank you.

Chris
Mar 17 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a

Christian Christmann wrote:
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*,
std::basic_string<char, std::char_traits<char>, std::allocator<char>
>)::storeInfo' uses local type `areg_action(burm_state*,

std::basic_string<char, std::char_traits<char>, std::allocator<char>
>)::storeInfo'

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-lit...t.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

Mar 17 '06 #2

P: n/a
> 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;
}

Mar 17 '06 #3

P: n/a
TB
Christian Christmann skrev:
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;
}


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

--
TB @ SWEDEN
Mar 17 '06 #4

P: n/a
In article <44***********************@newsread2.arcor-online.net>,
Christian Christmann <pl*****@yahoo.de> wrote:
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;
}


This discusses a related issue with the same underlying reason:

http://www.comeaucomputing.com/techt...#stringliteral
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Mar 17 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.