473,382 Members | 1,365 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,382 software developers and data experts.

const related error from Intel and g++ compiler but not from VC8.0

Hi there
So I am getting these error messages from Intel (v10) and g++ (v4.1.2) compilers respectively:
"error: the object has cv-qualifiers that are not compatible with the member function. object type is: const element"
"error: passing 'const Tetelement' as 'this' argument of 'void element:setID(long int)' discards qualifiers"
But the same code gets compiled using Microsfot VC8.0 compiler with no errors!

After a quick search, I figured that I need to make sure that I am not passing a const object to a non-const function/member.
To my knowledge I am not doing that, here is portion of my code that I think is relevant:

This is the part that invokes the error:

Expand|Select|Wrap|Line Numbers
  1. std::list<Tetelement> TetMesh::GetSortedElementList() {
  2. int counter = 0;
  3. std::set<Tetelement,Tetelm_less>::iteratorit;
  4.     for (it=myelms.begin();it!=myelms.end();++it) {
  5.         (*it).setID(++counter); // error line 
  6.         this->sortedtetlist.push_back(*it);
  7.     }
  8.         return this->sortedtetlist;
  9. }
Tetelement is a class derived from 'element' class in which 'setID()' is defined:

Expand|Select|Wrap|Line Numbers
  1. class element {
  2. public:
  3. // irrelevant code
  4.       inline void setID(long int idn) { id = idn;}
  5. private:
  6.       long int id;
  7. };
  8.  
  9.  
  10. class Tetelement : public element {
  11. // some code
  12. };
As you can see 'it' iterator is _not_ defined as const_iterator and setID() is also a non-const member.

Now... the following change resolves the error in both compilers:

Expand|Select|Wrap|Line Numbers
  1. Tetelement temp_tet = *it;
  2. temp_Tet.setID(counter);
So, is this related to how iterators are de-referenced under Intel and g++ compilers or Microsoft compiler is just ignoring my mistake and doing something behind the scene to fix the problem.

thanks for your time in advance :)
Sep 19 '07 #1
3 2220
weaknessforcats
9,208 Expert Mod 8TB
There are no errors. Older non-compliant compilers treat the members of a set container as const. set members are non-const. However, to change them, they need to be deleted and re-added. Otherwise the set structure is compromised.

When you add objects to a set, you can provide a key_compare object to compare keys. So long as you do not change the values of the set object used in the key_compare, you can update the set object. For this reason set objects are non-const.
Sep 24 '07 #2
There are no errors. Older non-compliant compilers treat the members of a set container as const. set members are non-const. However, to change them, they need to be deleted and re-added. Otherwise the set structure is compromised.

When you add objects to a set, you can provide a key_compare object to compare keys. So long as you do not change the values of the set object used in the key_compare, you can update the set object. For this reason set objects are non-const.
Thanks for your very informative post.
SetID() function in the original post doesn't change anything that is being used by my key_compare object (Tet_less).
But this is kinda of annoying, now I can't use the same source code under different compilers :(

So would it be alright to assume that intel and g++ comilers are non-compliant ?
Nov 7 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
So would it be alright to assume that intel and g++ comilers are non-compliant ?
I am not a g++ expert, but I have heared that there is a -pedantic switch that forces ANSI compliance.

However, to a greater or lesser extent, all compilers are non-compliant.
Nov 7 '07 #4

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

Similar topics

4
by: Jim West | last post by:
The following compiles with g++ 3.3.2, but fails with Intel icc 7.1 with the error: asdf.cc(6): error: expression must be an lvalue or a function designator f1(&arr); Is this undefined...
2
by: Alexander Malkis | last post by:
//Consider: class A { /*...*/ }; template<class T> class list {/*... */ }; void f(const list<const A*> lst) { /*...doesn't change the arg...*/ } void g(list<A*> lst) { f(lst);...
0
by: Ryan Mitchley | last post by:
Hi all The Intel compiler generates a #383 remark: "value copied to temporary, reference to temporay used", for both of the following lines: const complex<FTYPE> CBase::m_cfZero =...
3
by: H. S. | last post by:
Hi, I am trying to compile these set of C++ files and trying out class inheritence and function pointers. Can anybody shed some light why my compiler is not compiling them and where I am going...
6
by: David Lack | last post by:
Hi, I recently installed a 60-day trial of .NET 2003 on my development system. I made tests with previous personal projects (which compiled ok with VC6) and some open source files, and keep...
4
by: hweekuan | last post by:
Hi, I got an error with gnu C++ but not with intel C++ (icc). The distilled code is given below, a variable "T" is stored as a const T& in the base class and when the derived class try to access...
5
by: sean345 | last post by:
While compiling my program I get the following g++ error: error: no matching function for call to `ErrorLog::file_error(std::string&, std::string&, const char)' note: candidates are: void...
2
by: Faheem Mitha | last post by:
Hi, The following bit of code compiles fine with gcc 3.3 or later, but has problems with the Intel C++ compiler version 9.1, which produces the following error message. Is this a compiler...
13
by: asm23 | last post by:
Hi,I need some help to clarify the warning "initial value of reference to non-const must be an lvalue". I'm searching in this groups to find someone has the same situation like me. I found in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.