473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Assignment error with user defined vector container

2
Hi,
Following program compiles and executes successfully in windows. When I compile the same in Linux with 'g++323' compiler I get assignment error as:

cannot convert `__gnu_cxx::__normal_iterator<DailyTemp*,
std::vector<DailyTemp, std::allocator<DailyTemp> > >' to `DailyTemp*'
in assignment

I believe the overloaded assignment operation is unable to recognize the iterator. Can anyone help me to over come this issue?

Thanks.

// Store a class object in a vector.
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;

class DailyTemp {
double temp;
public:

//constructors
DailyTemp() { temp = 0; }
DailyTemp(double x) { temp = x; }

//assignment
DailyTemp &operator=(DailyTemp& x) {
temp = x.get_temp(); return *this;
}

///member functions
double get_temp() { return temp; }

};
bool operator<(DailyTemp a, DailyTemp b)
{
return a.get_temp() < b.get_temp();
}

bool operator==(DailyTemp a, DailyTemp b)
{
return (a.get_temp() == b.get_temp());
}

//Main routine
int main()
{

vector<DailyTemp> *v =new vector<DailyTemp>();

int i;
int search = 70;

DailyTemp dummy(78);
DailyTemp* dummy1;

for(i=0; i<7; i++)
v->push_back(DailyTemp(60 + rand()%30));


cout << "Farenheit temperatures:\n";

for(i=0; i<v->size(); i++)
cout << ((*v)[i]).get_temp() << " ";

cout << endl;

//Finding an entry in the vector
vector<DailyTemp>::iterator found;

found = find(v->begin(),v->end(),dummy);

if(found == v->end())
cout<<search<< " NOT FOUND"<<endl;
else
{
cout<<"found: "<<(*found).get_temp()<<endl;
dummy1 = found; //<<ERROR: Assignment fails with g++ >>

cout<<"found: "<<dummy1->get_temp()<<endl;
}

double result;
// convert from Farenheit to Centigrade
cout<<endl;
for(i=0; i<v->size(); i++)
{
result = ((*v)[i].get_temp()-32) * 5/9 ;
//cout <<result;
DailyTemp result1(result);
((*v)[i]) = result1;

}
cout<<endl;
cout << "Centigrade temperatures:\n";

for(i=0; i<v->size(); i++)
cout << (*v)[i].get_temp() << " ";


system("PAUSE");
return 0;
}
Nov 12 '06 #1
2 1346
horace1
1,510 Expert 1GB
if you remove
DailyTemp* dummy1;

and define dummy1 so
vector<DailyTemp>::iterator found, dummy1;

it should be Ok
Nov 12 '06 #2
Soofy
2
if you remove
DailyTemp* dummy1;

and define dummy1 so
vector<DailyTemp>::iterator found, dummy1;

it should be Ok

But could you please tell me why the reported issue occurs? I am interested to know the reason and want the code that way.. meaning dummy1 to be of type DailyTemp.

DailyTemp* dummy1;
and assign the found member to this variable.
Nov 12 '06 #3

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

Similar topics

8
by: Clifton M. Bean | last post by:
First, I defined three classes (listed below): =========== // 1st class =========== class PointCl { public: PointCl & operator= (const PointCl & rgh ); //define as usual assingment operator
67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
9
by: Gyro | last post by:
Dear All! Why there is no operator= for any type? I trying: typedef float mtx; operator=(mtx a, mtx b) { } compiler compaints that error: "operator=" must be a member function
7
by: Mr. Ed | last post by:
I have a base class which has about 150 derived classes. Most of the derived classes are very similar, and many don't change the base class at all. All the derived classes have a unique factory...
1
by: tim | last post by:
Our coding standard checker is reporting an implicit user conversion for the following: === std::vector<PepLines>* ptr = NULL; std::map<peppage::ePepPage, std::vector<PepLines>*>::iterator...
1
by: Raghuram N K | last post by:
Hi, Following program compiles and executes successfully in windows with DevCPP compiler. When I compile the same in Linux with 'g++323' compiler I get following assignment error: cannot...
22
by: =?gb2312?B?wNbA1rTzzOzKpg==?= | last post by:
windows xp, visual studio 2005 ---------------------------------------------------------------------------------------------------------------------------------- #include <iostream> #include <map>...
7
by: anupamsps | last post by:
HI all, let me explain the problem: In my simulation I am using two class: particle and Container. //////////// the outline of particle class/////////////////////...
6
by: hsmit.home | last post by:
Hello, I came across a strange error and it's really been bugging me. Maybe someone else has come across this and any insight would be appreciated. What I'm trying to accomplish is using...
12
by: hweekuan | last post by:
hi, it seems i can't assign the const variable u in class A, one way to solve the problem may be to build a copy constructor. however, why does C++ or vector class not like this code? my g++ is:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.