Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > structs and STL stack

Reply
Thread Tools

structs and STL stack

 
 
Christian Christmann
Guest
Posts: n/a
 
      03-17-2006
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
 
Reply With Quote
 
 
 
 
Gavin Deane
Guest
Posts: n/a
 
      03-17-2006

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

 
Reply With Quote
 
 
 
 
Christian Christmann
Guest
Posts: n/a
 
      03-17-2006
> 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;
}

 
Reply With Quote
 
TB
Guest
Posts: n/a
 
      03-17-2006
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
 
Reply With Quote
 
Greg Comeau
Guest
Posts: n/a
 
      03-17-2006
In article <441b04e0$0$21668$>,
Christian Christmann <> 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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C/C++ compilers have one stack for local variables and return addresses and then another stack for array allocations on the stack. Casey Hawthorne C Programming 3 11-01-2009 08:23 PM
Packed structs vs. unpacked structs: what's the difference? Daniel Rudy C Programming 15 04-10-2006 08:10 AM
Array of structs instead of an array with pointers to structs? Paminu C Programming 5 10-11-2005 07:18 PM
const structs in other structs Chris Hauxwell C Programming 6 04-27-2004 07:03 PM
structs with fields that are structs Patricia Van Hise C Programming 5 04-05-2004 01:37 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57