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

Can I use a local struct to store data in the "set" conatiner?

P: 5
Can I use a local struct to store data in the "set" conatiner? If so, what is the correct method to do so?

Compiler: Sun Studio 10 on Unix (Sun Solaris)

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<set>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.   struct product
  9.   {
  10.     int id;
  11.     string desc;
  12.     double amt;
  13.   } prdt;
  14.  
  15.   prdt.id = 1234;
  16.   prdt.desc = "Credit Card";
  17.   prdt.amt = 1000.00 ;
  18.  
  19.   cout << " This is a program to test set conatainer. " << endl
  20.        << " Product ID is: " << prdt.id 
  21.        << ", Product Desc is : " << prdt.desc 
  22.        << ", Credit Card Limit is : " << prdt.amt << endl ;
  23.  
  24.  
  25. [COLOR="DarkRed"]// Test program for 'set' container with a struct
  26.  typedef std::set< product, std::less< int > > product_set;[/COLOR]
  27.  
  28.   return 0;
  29. }
  30.  
  31.  

Error Message:[COLOR="DarkRed"]"testSet.c", line 26: Error: The local type "product" cannot be used as a template argument.
"/opt/SunStudio10/SUNWspro/prod/include/CC/Cstd/./set", line 83: Error: The local type "product" cannot be used as a template argument.[/COLOR]
Dec 6 '06 #1
Share this Question
Share on Google+
1 Reply


Banfa
Expert Mod 5K+
P: 8,916
basically, yes but it would help if you could post your code at least up to line 26 where the error occurs.
Dec 7 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.