1 Replies - 1371 Views - Last Post: 05 February 2011 - 02:28 AM Rate Topic: -----

#1 gothchicz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 26-January 10

Error in Pair when assigning structs (no match operator=)

Posted 04 February 2011 - 11:49 PM

Can someone please let me know whats wrong with this code?


const int MAX=50;
static int count; // for tracking array

struct Date
{
int day;
int month;
int year;

bool operator<(const Date& d) const
{
return this->day < d.day;
}
}date;

struct Goods
{
string item;
double price;
int purchased;
string date;
struct DateInner
{
int day;
int month;
int year;
}d;
//friend ostream& operator<<(ostream&, Date& d);

}goods;

void summary (Goods* goods,Date* date)
{

for(int i=0;i<count;i++)
{
printGoods(goods[i]);
}

cout << "Summary section" << endl;
double grandTotal = 0;
map<Date,double> totalSales;
pair<Date,double> aPair;

pair<map<Date,double>::iterator,bool> check;

map<Date,double>::iterator totalIter;


int i=0;
int idx=0;
while (i<count)
{
aPair.first = goods[idx].d; <------------------------------SOMETHING WRONG ???
aPair.second = goods[idx].price * goods[idx].purchased;

check = totalSales.insert(aPair);

if(check.second == false)
{
totalSales [aPair.first] = totalSales [aPair.first] + aPair.second;
}
i++;
idx++;

}


cout << "Date" << setw(19) << "Total Sales" <<endl;
cout<< "------------------------------"<<endl;
totalIter = totalSales.begin();
while (totalIter!=totalSales.end()--)
{
cout << totalIter->first << setw(15) << totalIter->second <<endl;
grandTotal = grandTotal + totalIter->second;
totalIter++;
}

cout << "Grand total: \t" << grandTotal <<endl;

}


ERROR MESSAGE
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/gothchicz/NetBeansProjects/Transa…
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/transaction
make[2]: Entering directory `/home/gothchicz/NetBeansProjects/Transa…
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
g++ -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/main.o main.cpp
main.cpp: In function ‘void summary(Goods*, Date*)’:
main.cpp:608: error: no match for ‘operator=’ in ‘aPair.std::pair<Date, double>::first = (goods + ((unsigned int)(((unsigned int)idx) * 32u)))->Goods::D/>’
main.cpp:18: note: candidates are: Date& Date::operator=(const Date&)
make[2]: *** [build/Debug/GNU-Linux-x86/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: Leaving directory `/home/gothchicz/NetBeansProjects/Transa…
make[1]: Leaving directory `/home/gothchicz/NetBeansProjects/Transa…

BUILD FAILED (exit value 2, total time: 1s)


Is This A Good Question/Topic? 0
  • +

Replies To: Error in Pair when assigning structs (no match operator=)

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Error in Pair when assigning structs (no match operator=)

Posted 05 February 2011 - 02:28 AM

I get 31 errors after adding the missing include statements and the "using namespace std;" statement.

You have a bunch of undeclared identifiers:

Error	1	error C2872: 'count' : ambiguous symbol
Error	2	error C3861: 'printGoods': identifier not found
Error	3	error C2065: 'map' : undeclared identifier
Error	4	error C2275: 'Date' : illegal use of this type as an expression
Error	5	error C2062: type 'double' unexpected
Error	6	error C2065: 'map' : undeclared identifier
Error	7	error C2275: 'Date' : illegal use of this type as an expression
Error	8	error C2955: 'std::pair' : use of class template requires template argument list
Error	9	error C2039: 'iterator' : is not a member of 'std::pair'
Error	10	error C2143: syntax error : missing ';' before ','
Error	11	error C2143: syntax error : missing ';' before ','
Error	12	error C2065: 'map' : undeclared identifier
Error	13	error C2275: 'Date' : illegal use of this type as an expression
Error	14	error C2062: type 'double' unexpected
Error	15	error C2872: 'count' : ambiguous symbol
Error	16	error C2679: binary '=' : no operator found which takes a right-hand operand of type 'Goods::DateInner' (or there is no acceptable conversion)
Error	17	error C2143: syntax error : missing ';' before '<'
Error	18	error C2065: 'check' : undeclared identifier
Error	19	error C2065: 'totalSales' : undeclared identifier
Error	20	error C2228: left of '.insert' must have class/struct/union
Error	21	error C2065: 'check' : undeclared identifier
Error	22	error C2228: left of '.second' must have class/struct/union
Error	23	error C2065: 'totalSales' : undeclared identifier
Error	24	error C2065: 'totalSales' : undeclared identifier
Error	25	error C2065: 'totalIter' : undeclared identifier
Error	26	error C2065: 'totalSales' : undeclared identifier
Error	27	error C2228: left of '.begin' must have class/struct/union
Error	28	error C2065: 'totalIter' : undeclared identifier
Error	29	error C2065: 'totalSales' : undeclared identifier
Error	30	error C2228: left of '.end' must have class/struct/union
Error	31	fatal error C1903: unable to recover from previous error(s); stopping compilation



Try fixing those for a start.

This post has been edited by n8wxs: 05 February 2011 - 02:35 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1