こんにちは。
質問させてください。
現在VisualStudio2008 Academic EditionでC++のプログラムを書いています。
vectorで使用可能なアロケータを作ったのですが、mapでそのアロケータを利用する方法がわかりません。
// vectorで自作アロケータを利用
std::vector< char, my_allocator<char> > myVec;
// mapで自作アロケータを利用
std::map< int, float, std::less< int >, my_allocator< std::pair< int, float > > > myMap;
vectorの場合はコンパイルできるのですがmapの場合は
error C2664: 'my_allocator<_type>::allocator(const my_allocator<_type> &)' : 1 番目の引数を 'my_allocator<_type>' から 'const my_allocator<_type> &' に変換できません。
というエラーが出てコンパイルできません。
ご教授願います。
No.2ベストアンサー
- 回答日時:
std::map が value_type のための rebind 定義を別途要求するせいだと思われます。
下記のコンストラクタは定義していますか?
my_allocator() throw(){}
my_allocator(const my_allocater<_Ty>&) throw(){}
template <class _Other> my_allocator(const allocator<_Other>&) throw(){}
value_type に key_type と同様のカスタム アロケート処理を行なう場合、空の定義でかまわないようです。
参考までに。
http://www.geocities.jp/ky_webid/cpp/library/028 …
http://monsho.blog63.fc2.com/blog-entry-93.html
No.1
- 回答日時:
std::map< int, float, std::less< int >, my_allocator< std::pair< const int, float > > > myMap;
ではないでしょうか?
ちなみに私の環境はVS2005ですが
std::map< int, float, std::less< int >, my_allocator< std::allocator< int, float > > > myMap;
でコンパイルが通りますが2008だと型に厳しくなっているのかもしれません。
もし、std::map< int, float, std::less< int >, std::allocator< std::pair< const int, float > > > myMap;
でコンパイルが通るならアロケータの実装に問題があるように思います。
ソースはついていると思うのでstd::allocatorのソースとmy_allocatorを比較してみるとよいでしょう。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
- ・ゆるやかでぃべーと タイムマシンを破壊すべきか。
- ・歩いた自慢大会
- ・許せない心理テスト
- ・字面がカッコいい英単語
- ・これ何て呼びますか Part2
- ・人生で一番思い出に残ってる靴
- ・ゆるやかでぃべーと すべての高校生はアルバイトをするべきだ。
- ・初めて自分の家と他人の家が違う、と意識した時
- ・単二電池
- ・チョコミントアイス
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
空ENTERの判別
-
switch文のエラーについて
-
VC++で文字列から任意の文字を...
-
VS2019でofstreamが未定義になる
-
LinuxのQtに関する質問です。
-
#include "fstream.h"
-
リモートデスクトップの接続元I...
-
CStringとString
-
Visial C++おけるπの使い方
-
gccでコンパイル時のエラー
-
uniqueの使い方について
-
#defineの使い方について
-
C++ 文字列とポインタ、STL::ma...
-
C++でShowCursorを使いたい。
-
【C++】ヘッダ内でstringを格納...
-
C++ std::threadを引数で受け取...
-
STLでポインタのリストをsort()...
-
MingwでC++のソースがコンパイ...
-
構文エラーが出ているのですが...
-
VHDLのsignedとunsignedの違いは?
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
switch文のエラーについて
-
構文エラーが出ているのですが...
-
なぜ、C++の標準ヘッダをインク...
-
gccでコンパイル時のエラー
-
空ENTERの判別
-
【C++】ヘッダ内でstringを格納...
-
snprintfが使用できない。
-
enumの値から定義名を文字列化...
-
#include "fstream.h"
-
C++で、テキストファイルを一行...
-
std::wstringのメモリリークに...
-
C++での <iostream.h>と<iostre...
-
VC++で文字列から任意の文字を...
-
#defineの使い方について
-
wstringの主力
-
vc++の使い方について
-
std::map の const 修飾について
-
string型のフォーマット書式指...
-
構造体配列のvectorへの変換と...
-
指定した文字を削除したい
おすすめ情報