H
Heiko Hund
Hi,
I do not understand the deeper reason for the following compiler error
$ g++ test.cpp
test.cpp: In function `int main()':
test.cpp:41: error: `std::basic_string<char, std::char_traits<char>,
std::allocator<char> >' is an inaccessible base of `Path'
I'm using Debians
$ g++ --version
g++ (GCC) 3.3.5 (Debian 1:3.3.5-8)
$ dpkg -l libstdc++5
ii libstdc++5 3.3.5-8 The GNU Standard C++ Library v3
Here the source code that produces the problem:
#include <string>
class Path : private std::string
{
public:
Path(std::string const & p)
:std::string(p)
{}
Path(Path const & rhs)
:std::string(rhs)
{}
operator std::string() const
{
return static_cast<std::string>(*this);
}
operator std::string const() const
{
return static_cast<std::string const>(*this);
}
operator std::string const &() const
{
return static_cast<std::string const &>(*this);
}
operator char const *() const
{
return c_str();
}
};
int main()
{
Path p("foo");
Path p2(p);
char const * c(p);
std::string s(p); // <- error
return 0;
}
Any enlightenment is highly appreciated.
Thanks
Heiko
I do not understand the deeper reason for the following compiler error
$ g++ test.cpp
test.cpp: In function `int main()':
test.cpp:41: error: `std::basic_string<char, std::char_traits<char>,
std::allocator<char> >' is an inaccessible base of `Path'
I'm using Debians
$ g++ --version
g++ (GCC) 3.3.5 (Debian 1:3.3.5-8)
$ dpkg -l libstdc++5
ii libstdc++5 3.3.5-8 The GNU Standard C++ Library v3
Here the source code that produces the problem:
#include <string>
class Path : private std::string
{
public:
Path(std::string const & p)
:std::string(p)
{}
Path(Path const & rhs)
:std::string(rhs)
{}
operator std::string() const
{
return static_cast<std::string>(*this);
}
operator std::string const() const
{
return static_cast<std::string const>(*this);
}
operator std::string const &() const
{
return static_cast<std::string const &>(*this);
}
operator char const *() const
{
return c_str();
}
};
int main()
{
Path p("foo");
Path p2(p);
char const * c(p);
std::string s(p); // <- error
return 0;
}
Any enlightenment is highly appreciated.
Thanks
Heiko