基本クラス テンプレートが文字列にアクセスできるように、文字列リテラルをテンプレート パラメーターとして使用する次のコード例があります。
コードはコンパイルされますが、完全には理解できない警告が表示されます。
警告: 'ns::bar::type' にはベース 'ns::base<((const char*)(& ns::bar::name))>' があり、その型は匿名名前空間を使用します [デフォルトで有効]
以下の作業例コード:
// "test.h"
#pragma once
namespace ns
{
template <char const* str>
struct base
{
const char *name() const { return str; }
};
namespace bar
{
static constexpr char name[] = "bar";
struct type : base<name> {}; // <-- this line here
}
}
// main.cpp
#include <iostream>
#include "test.h"
int main()
{
ns::bar::type f;
std::cout << f.name() << std::endl;
return 0;
}
だから私の質問は:
- この警告はどういう意味ですか?
- ここで行っている方法で、文字列リテラルをテンプレート パラメーターとして渡すことは安全ですか?
(これは gcc 4.7.2 であることに注意してください)