Connecting Tech Pros Worldwide Help | Site Map

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

Newbie
 
Join Date: Oct 2006
Posts: 5
#1: Dec 6 '06
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]
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,161
#2: Dec 7 '06

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


basically, yes but it would help if you could post your code at least up to line 26 where the error occurs.
Reply