スレッド: [cppll_novice:0669] typedef でクラステンプレート
スレッド
- 669: 以下のプログラムを VC++ 6.0 でビルドしようとすると、return の行 で「静的でないメンバ関数の Imabeppu
- ├670: きっとVC6の'やるせない'事情。VC7.1だと呑んでくれますもん。 typename std::multimap<std::string, T>::size_ FUKUDA Fumiki
- │├671: なるほど……。VC6 ではだめなんですね。ちなみに、 using namespace std を使うと通りました。 using Imabeppu
- ││└673: 正しいはず。Tが明らかでないうちは std::multimap<std::string, T>::size_type が型かどうかわかんない。 FUKUDA Fumiki
- │└672: C++ Templates: The Complete Guide の45ページの 5.2 Using this-> に同様の内容のソースコードがありました. Toru SHIBUYA
- │ └686: 失敗ついでに... template<class T> class Test : public std::multimap<std::string, T> { public: using std::multimap< std::st Toru SHIBUYA
- └688: ちわ。 二つあります。 ・std::multimap<std::string, T>::count()がメソッド名として認識され てる? 推測 Shin'ya MORINO
- └716: これが、επιστημηさんが書かれていた「VC6 の 'やるせない' 事情」なんですね。 いずれも typ Imabeppu
[cppll_novice:0669] typedef でクラステンプレート
- Subject:
- [cppll_novice:0669] typedef でクラステンプレート
- From:
- Imabeppu <imabeppu@...>
- Date:
- Fri, 10 Dec 2004 11:52:22 +0900
- X-Mailer:
- Becky! ver. 2.12.01 [ja]
- Message-Id:
- <20041210113548.FA12.IMABEPPU‐at‐osl.fujitsu.com>
Imabeppu です。
以下のプログラムを VC++ 6.0 でビルドしようとすると、return の行
で「静的でないメンバ関数の中で呼び出しが正しくありません。」とい
うエラーが出てしまいます。親クラスを呼び出したいだけなんですが、
なぜなんでしょう?
#include <map>
#include <string>
template<class T>
class Test : public std::multimap<std::string, T>
{
public:
std::multimap<std::string, T>::size_type count(const std::string& key) const
{
return std::multimap<std::string, T>::count(key);
}
};
int main(……)
{
Test<int> test;
test.count("TEST");
:
}
--
|===== ∧ ∧ ===============|
|== n(=⌒o⌒=)n Imabeppu ==|
以下のプログラムを VC++ 6.0 でビルドしようとすると、return の行
で「静的でないメンバ関数の中で呼び出しが正しくありません。」とい
うエラーが出てしまいます。親クラスを呼び出したいだけなんですが、
なぜなんでしょう?
#include <map>
#include <string>
template<class T>
class Test : public std::multimap<std::string, T>
{
public:
std::multimap<std::string, T>::size_type count(const std::string& key) const
{
return std::multimap<std::string, T>::count(key);
}
};
int main(……)
{
Test<int> test;
test.count("TEST");
:
}
--
|===== ∧ ∧ ===============|
|== n(=⌒o⌒=)n Imabeppu ==|
[cppll_novice:0670] Re:typedef でクラステンプレート
- Subject:
- [cppll_novice:0670] Re:typedef でクラステンプレート
- From:
- FUKUDA Fumiki <fukuda.fm@...>
- Date:
- Fri, 10 Dec 2004 12:01:45 +0900
- X-Mailer:
- WeMail32[1.42] ID:NTES00
- Message-Id:
- <200412100307.iBA37L618524‐at‐mailsv3.nec.co.jp>
- In-Reply-To:
- 669
επιστημηです。
>以下のプログラムを VC++ 6.0 でビルドしようとすると、return の行
>で「静的でないメンバ関数の中で呼び出しが正しくありません。」とい
>うエラーが出てしまいます。親クラスを呼び出したいだけなんですが、
>なぜなんでしょう?
きっとVC6の'やるせない'事情。VC7.1だと呑んでくれますもん。
typename std::multimap<std::string, T>::size_type count(const std::string& key) const
^^^^^^^^
さえくっつけてあげれば。
-----:-----:-----:-----:-----:-----:-----:-----:-----:-----
FUKUDA (episteme) Fumiki -- magical, but never a magic...
>以下のプログラムを VC++ 6.0 でビルドしようとすると、return の行
>で「静的でないメンバ関数の中で呼び出しが正しくありません。」とい
>うエラーが出てしまいます。親クラスを呼び出したいだけなんですが、
>なぜなんでしょう?
きっとVC6の'やるせない'事情。VC7.1だと呑んでくれますもん。
typename std::multimap<std::string, T>::size_type count(const std::string& key) const
^^^^^^^^
さえくっつけてあげれば。
-----:-----:-----:-----:-----:-----:-----:-----:-----:-----
FUKUDA (episteme) Fumiki -- magical, but never a magic...
[cppll_novice:0671] Re: typedef でクラステンプレート
Imabeppu です。
Quoted from
Subject: [cppll_novice:0670] Re:typedef でクラステンプレート
From: FUKUDA Fumiki <fukuda.fm@...>
Date: 2004/12/10 12:01:45 (Fri, 10 Dec 2004 12:01:45 +0900)
> きっとVC6の'やるせない'事情。VC7.1だと呑んでくれますもん。
>
> typename std::multimap<std::string, T>::size_type count(const std::string& key) const
> ^^^^^^^^
> さえくっつけてあげれば。
なるほど……。VC6 ではだめなんですね。ちなみに、
using namespace std を使うと通りました。
#include <map>
#include <string>
using namespace std
template<class T>
class Test : public multimap<string, T>
{
public:
multimap<string, T>::size_type count(const string& key) const
{
return multimap<string, T>::count(key);
}
};
int main(……)
{
Test<int> test;
test.count("TEST");
:
}
VC7 では typename をつければ通るとのことですが、つけないと通ら
ないのは正しい動きなんでしょうか?
--
|===== ∧ ∧ ===============|
|== n(=⌒o⌒=)n Imabeppu ==|
Quoted from
Subject: [cppll_novice:0670] Re:typedef でクラステンプレート
From: FUKUDA Fumiki <fukuda.fm@...>
Date: 2004/12/10 12:01:45 (Fri, 10 Dec 2004 12:01:45 +0900)
> きっとVC6の'やるせない'事情。VC7.1だと呑んでくれますもん。
>
> typename std::multimap<std::string, T>::size_type count(const std::string& key) const
> ^^^^^^^^
> さえくっつけてあげれば。
なるほど……。VC6 ではだめなんですね。ちなみに、
using namespace std を使うと通りました。
#include <map>
#include <string>
using namespace std
template<class T>
class Test : public multimap<string, T>
{
public:
multimap<string, T>::size_type count(const string& key) const
{
return multimap<string, T>::count(key);
}
};
int main(……)
{
Test<int> test;
test.count("TEST");
:
}
VC7 では typename をつければ通るとのことですが、つけないと通ら
ないのは正しい動きなんでしょうか?
--
|===== ∧ ∧ ===============|
|== n(=⌒o⌒=)n Imabeppu ==|
[cppll_novice:0673] Re: typedef でクラステンプレート
- Subject:
- [cppll_novice:0673] Re: typedef でクラステンプレート
- From:
- FUKUDA Fumiki <fukuda.fm@...>
- Date:
- Fri, 10 Dec 2004 13:26:21 +0900
- X-Mailer:
- WeMail32[1.42] ID:NTES00
- Message-Id:
- <200412100431.iBA4Vs417251‐at‐mailsv5.nec.co.jp>
- In-Reply-To:
- 671
επιστημηです。
>> typename std::multimap<std::string, T>::size_type count(const std::string& key) const
>> ^^^^^^^^
> VC7 では typename をつければ通るとのことですが、つけないと通ら
> ないのは正しい動きなんでしょうか?
正しいはず。Tが明らかでないうちは
std::multimap<std::string, T>::size_type が型かどうかわかんない。
だからコンパイラに'型ですカラ!'と教えてあげるためにtypenameつけるです。
-----:-----:-----:-----:-----:-----:-----:-----:-----:-----
FUKUDA (episteme) Fumiki -- magical, but never a magic...
>> typename std::multimap<std::string, T>::size_type count(const std::string& key) const
>> ^^^^^^^^
> VC7 では typename をつければ通るとのことですが、つけないと通ら
> ないのは正しい動きなんでしょうか?
正しいはず。Tが明らかでないうちは
std::multimap<std::string, T>::size_type が型かどうかわかんない。
だからコンパイラに'型ですカラ!'と教えてあげるためにtypenameつけるです。
-----:-----:-----:-----:-----:-----:-----:-----:-----:-----
FUKUDA (episteme) Fumiki -- magical, but never a magic...
[cppll_novice:0672] Re:typedef でクラステンプレート
- Subject:
- [cppll_novice:0672] Re:typedef でクラステンプレート
- From:
- Toru SHIBUYA <ferrite@...>
- Date:
- Fri, 10 Dec 2004 13:07:10 +0900
- Message-Id:
- <41B920EE.1070006‐at‐k4.dion.ne.jp>
- In-Reply-To:
- 670
- References:
- 670
こんにちわ.渋谷です.
C++ Templates: The Complete Guide
の45ページの 5.2 Using this->
に同様の内容のソースコードがありました.
これによれば最初のコードのように,
return std::multimap<std::string, T>::count(key);
とするか,
return this->count(key);
でコンパイルできそうですが...
g++.exe (GCC) 3.4.0 (mingw special)では↓の修正をすれば,
どっちもとおしてくれました.
FUKUDA Fumiki wrote:
> typename std::multimap<std::string, T>::size_type count(const std::string& key) const
> ^^^^^^^^
--
Toru SHIBUYA
C++ Templates: The Complete Guide
の45ページの 5.2 Using this->
に同様の内容のソースコードがありました.
これによれば最初のコードのように,
return std::multimap<std::string, T>::count(key);
とするか,
return this->count(key);
でコンパイルできそうですが...
g++.exe (GCC) 3.4.0 (mingw special)では↓の修正をすれば,
どっちもとおしてくれました.
FUKUDA Fumiki wrote:
> typename std::multimap<std::string, T>::size_type count(const std::string& key) const
> ^^^^^^^^
--
Toru SHIBUYA
[cppll_novice:0686] Re: typedef でクラステンプレート
- Subject:
- [cppll_novice:0686] Re: typedef でクラステンプレート
- From:
- Toru SHIBUYA <ferrite@...>
- Date:
- Mon, 13 Dec 2004 13:54:04 +0900
- Message-Id:
- <41BD206C.6090105‐at‐k4.dion.ne.jp>
- In-Reply-To:
- *
- References:
- 670 672 * *
失敗ついでに...
template<class T>
class Test : public std::multimap<std::string, T>
{
public:
using std::multimap< std::string, T >::count;
};
でもいけました.
この場合ですとpublic継承しているのでusing
してもしてなくても同じですが,
private継承した場合でも使えます.
--
Toru SHIBUYA
template<class T>
class Test : public std::multimap<std::string, T>
{
public:
using std::multimap< std::string, T >::count;
};
でもいけました.
この場合ですとpublic継承しているのでusing
してもしてなくても同じですが,
private継承した場合でも使えます.
--
Toru SHIBUYA
[cppll_novice:0688] Re: typedef でクラステンプレート
- Subject:
- [cppll_novice:0688] Re: typedef でクラステンプレート
- From:
- Shin'ya MORINO <smorino@...>
- Date:
- Tue, 14 Dec 2004 02:26:53 +0900
- X-Mailer:
- Datula version 1.51.09 for Windows
- Message-Id:
- <41bdcece.5716%smorino‐at‐d1.dion.ne.jp>
- In-Reply-To:
- 669
- References:
- 669
森野@茶々になったらごめんなさい です。
Imabeppuさんの<20041210113548.FA12.IMABEPPU@osl.fujitsu.com>から
>Imabeppu です。
ちわ。
>以下のプログラムを VC++ 6.0 でビルドしようとすると、return の行
>で「静的でないメンバ関数の中で呼び出しが正しくありません。」とい
>うエラーが出てしまいます。親クラスを呼び出したいだけなんですが、
>なぜなんでしょう?
二つあります。
・std::multimap<std::string, T>::size_type が型と認識されてる?
-> これは大丈夫かも。ごめんなさい。試してないです。
・std::multimap<std::string, T>::count()がメソッド名として認識され
てる?
推測ではこれがダメ。
VC6ではstd::multimap'<' の時点で、'<'が不等号(つーか'小なり'ですね
。)と解釈されているフシがあります。
テンプレートメソッドの明示的なインスタンシングにおいても、メソッド名
に'<'を使うの、ためらわれます。 >> VC6
ということで、VC6でも動くかもしれないなと思う書き直し案二つ。
> #include <map>
> #include <string>
>
> template<class T>
> class Test : public std::multimap<std::string, T>
> {
-------------------
> public:
> std::multimap<std::string, T>::size_type count(const
>std::string& key) const
> {
> return std::multimap<std::string, T>::count(key);
> }
案1---------------
// もしかして、typenameつけたらエラーかも。
typedef typename std::multimap<std::string, T> parent_type;
typedef parent_type::size_type size_type;
public:
size_type count(const std::string &key) const {
return static_cast<parent_type*>(this)->count(key);
}
案2---------------
// もしかして、typenameつけたらエラーかも。
typedef typename std::multimap<std::string, T> parent_type;
typedef parent_type::size_type size_type;
public:
size_type count(const std::string &key) const {
return parent_type::count(key);
}
-------------------
> };
--
Shin'ya MORINO mailto:smorino@...
Imabeppuさんの<20041210113548.FA12.IMABEPPU@osl.fujitsu.com>から
>Imabeppu です。
ちわ。
>以下のプログラムを VC++ 6.0 でビルドしようとすると、return の行
>で「静的でないメンバ関数の中で呼び出しが正しくありません。」とい
>うエラーが出てしまいます。親クラスを呼び出したいだけなんですが、
>なぜなんでしょう?
二つあります。
・std::multimap<std::string, T>::size_type が型と認識されてる?
-> これは大丈夫かも。ごめんなさい。試してないです。
・std::multimap<std::string, T>::count()がメソッド名として認識され
てる?
推測ではこれがダメ。
VC6ではstd::multimap'<' の時点で、'<'が不等号(つーか'小なり'ですね
。)と解釈されているフシがあります。
テンプレートメソッドの明示的なインスタンシングにおいても、メソッド名
に'<'を使うの、ためらわれます。 >> VC6
ということで、VC6でも動くかもしれないなと思う書き直し案二つ。
> #include <map>
> #include <string>
>
> template<class T>
> class Test : public std::multimap<std::string, T>
> {
-------------------
> public:
> std::multimap<std::string, T>::size_type count(const
>std::string& key) const
> {
> return std::multimap<std::string, T>::count(key);
> }
案1---------------
// もしかして、typenameつけたらエラーかも。
typedef typename std::multimap<std::string, T> parent_type;
typedef parent_type::size_type size_type;
public:
size_type count(const std::string &key) const {
return static_cast<parent_type*>(this)->count(key);
}
案2---------------
// もしかして、typenameつけたらエラーかも。
typedef typename std::multimap<std::string, T> parent_type;
typedef parent_type::size_type size_type;
public:
size_type count(const std::string &key) const {
return parent_type::count(key);
}
-------------------
> };
--
Shin'ya MORINO mailto:smorino@...
[cppll_novice:0716] Re: typedef でクラステンプレート
Imabeppu です。
Quoted from
Subject: [cppll_novice:0688] Re: typedef でクラステンプレート
From: "Shin'ya MORINO" <smorino@...>
Date: 2004/12/14 2:26:53 (Tue, 14 Dec 2004 02:26:53 +0900)
> VC6ではstd::multimap'<' の時点で、'<'が不等号(つーか'小なり'ですね
> 。)と解釈されているフシがあります。
これが、επιστημηさんが書かれていた「VC6 の 'やるせない'
事情」なんですね。
> ということで、VC6でも動くかもしれないなと思う書き直し案二つ。
:
> 案1---------------
> // もしかして、typenameつけたらエラーかも。
> typedef typename std::multimap<std::string, T> parent_type;
> typedef parent_type::size_type size_type;
> public:
> size_type count(const std::string &key) const {
> return static_cast<parent_type*>(this)->count(key);
> }
> 案2---------------
> // もしかして、typenameつけたらエラーかも。
> typedef typename std::multimap<std::string, T> parent_type;
> typedef parent_type::size_type size_type;
> public:
> size_type count(const std::string &key) const {
> return parent_type::count(key);
> }
> -------------------
いずれも
typedef typename std::multimap<std::string, T> parent_type;
がだめでした。
型名はテンプレート宣言の外側で使用できません。
だそうです。typename を外して試してみたところ、
'T' : 定義されていない識別子です。
だそうで、typedef できませんから。残念!! VC6 切腹!! (^^)
ありがとうございました。
--
|===== ∧ ∧ ===============|
|== n(=⌒o⌒=)n Imabeppu ==|
Quoted from
Subject: [cppll_novice:0688] Re: typedef でクラステンプレート
From: "Shin'ya MORINO" <smorino@...>
Date: 2004/12/14 2:26:53 (Tue, 14 Dec 2004 02:26:53 +0900)
> VC6ではstd::multimap'<' の時点で、'<'が不等号(つーか'小なり'ですね
> 。)と解釈されているフシがあります。
これが、επιστημηさんが書かれていた「VC6 の 'やるせない'
事情」なんですね。
> ということで、VC6でも動くかもしれないなと思う書き直し案二つ。
:
> 案1---------------
> // もしかして、typenameつけたらエラーかも。
> typedef typename std::multimap<std::string, T> parent_type;
> typedef parent_type::size_type size_type;
> public:
> size_type count(const std::string &key) const {
> return static_cast<parent_type*>(this)->count(key);
> }
> 案2---------------
> // もしかして、typenameつけたらエラーかも。
> typedef typename std::multimap<std::string, T> parent_type;
> typedef parent_type::size_type size_type;
> public:
> size_type count(const std::string &key) const {
> return parent_type::count(key);
> }
> -------------------
いずれも
typedef typename std::multimap<std::string, T> parent_type;
がだめでした。
型名はテンプレート宣言の外側で使用できません。
だそうです。typename を外して試してみたところ、
'T' : 定義されていない識別子です。
だそうで、typedef できませんから。残念!! VC6 切腹!! (^^)
ありがとうございました。
--
|===== ∧ ∧ ===============|
|== n(=⌒o⌒=)n Imabeppu ==|