473,770 Members | 5,299 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

make_pair with auto_ptr: ... discards qualifiers

I am trying to make a pair with a string and an auto_ptr:

#include <iostream>
#include <map>
using namespace std;

int main(){
auto_ptr<intp(n ew int(3));
make_pair("x",p );
}

But it won't compile:

stl_pair.h:85: error: passing `const std::auto_ptr<i nt>' as `t\
his' argument of `std::auto_ptr< _Tp>::operator
std::auto_ptr_r ef<_Tp1>() [with _Tp1 = int, _Tp = int]' discards
qualifiers

I didn't make p const, so I don't understand why it complains ... How
can I make it work?

Aug 22 '06 #1
2 2973
Markus Dehmann wrote:
I am trying to make a pair with a string and an auto_ptr:

#include <iostream>
#include <map>
using namespace std;

int main(){
auto_ptr<intp(n ew int(3));
make_pair("x",p );
}

But it won't compile:

stl_pair.h:85: error: passing `const std::auto_ptr<i nt>' as `t\
his' argument of `std::auto_ptr< _Tp>::operator
std::auto_ptr_r ef<_Tp1>() [with _Tp1 = int, _Tp = int]' discards
qualifiers

I didn't make p const, so I don't understand why it complains ... How
can I make it work?
You can't make it work. 'std::pair's constructor takes arguments by
const ref. Inside it constructs the members using copy-construction.
'std::auto_ptr' constructor takes non-const ref as its argument.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 22 '06 #2
In article <11************ **********@i42g 2000cwa.googleg roups.com>,
"Markus Dehmann" <ma************ @gmail.comwrote :
I am trying to make a pair with a string and an auto_ptr:

#include <iostream>
#include <map>
using namespace std;

int main(){
auto_ptr<intp(n ew int(3));
make_pair("x",p );
}

But it won't compile:

stl_pair.h:85: error: passing `const std::auto_ptr<i nt>' as `t\
his' argument of `std::auto_ptr< _Tp>::operator
std::auto_ptr_r ef<_Tp1>() [with _Tp1 = int, _Tp = int]' discards
qualifiers

I didn't make p const, so I don't understand why it complains ... How
can I make it work?
Items in a pair must have standard copy and assignment semantics, and
auto_ptr doesn't.
Aug 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2353
by: stephen henry | last post by:
Hi all, I'm trying to create a vector of pointers to a class: For example: class CMb ... std::vector< CMb* > myvect(100);
6
95852
by: Jason | last post by:
I have a function (Inet_ntop) that returns const char * and if I try to assign that return value to a char * variable, I get the gcc error message: warning: assignment discards qualifiers from pointer target type Does anyone know what this warning means? Why do I get it? The program compiles and appears to work, but I'd like to understand the warning. Here is basically what the code looks like: char *str;
12
4888
by: Charlie Zender | last post by:
Hi, I am unable to compile a large body of code with extremely pedantic compile time checks activate, so that warnings cause errors. With GCC 3.3.1, I do this with gcc -std=c99 -pedantic -Wall -Wunused -Werror -W -Wmissing-prototypes -Wconversion -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -c -o foo.o foo.c
2
19098
by: John | last post by:
Hello! When I compile the following code, I get this error message "error: passing ... discards qualifiers" and I don't understand why. Could anybody help me? Thank you! John
4
4870
by: Lycan. Mao.. | last post by:
Hello, I'm trying to write a function adapter object, but it fails with the above information. Can you help me. template <typename _Predicate> struct Unary_negate { typedef typename _Predicate::argument_type argument_type; typedef typename _Predicate::return_type return_type; _Predicate pred_;
17
12788
by: Pietro Cerutti | last post by:
i Group, to my understanding, defining a function parameter as "const" means that the function is not going to change it. Why does the compiler says "return discards qualifiers from pointer target type" when I *access* a member of an argument defined as const? Please see the code below:
2
2259
by: Thelma Lubkin | last post by:
I use my own matrix and vector classes. I wrote them before such things were generally available and I've stuck with them ever since. I've just added an Octonion class derived from the vectors class and I'm trying to do some matrix arithmetic where the elements of the matrices are Octonions. (My Octonions are essentially 8-component vectors with a multiplication table that I compute at runtime. Like vectors, they are a template class, but...
4
8919
by: Andre | last post by:
Hi All, When I compile the following piece of code with gcc, I get 3 "warning: initialization discards qualifiers from pointer target type" messages which refer to the 3 lines marked in the code. What's wrong with these lines? I searched the web for it, but didn't find anything useful. Thanks,
8
4427
by: Ruben | last post by:
error: passing `const Weight' as `this' argument of `float Weight::wgt()' discards qualifiers seems to be some sort of standard error format that I'm not understanding. I have code that looks like this header file
0
9591
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10001
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8880
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3573
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.