S
subramanian100in
Consider the following program:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
template<class T> class Vec : public vector<T>
{
public:
Vec() : vector<T>() { }
Vec(int s) : vector<T>(s) { }
T& operator[] (int i) { return at(i); }
};
int main()
{
Vec<string> s(3);
return 0;
}
Suppose this program is named as y.cpp
When this program is compiled under Redhat Enterprise Linux
Workstation, as
g++ -std=c++98 -pedantic -Wall -Wextra y.cpp
I am getting the following compilation error:
y.cpp: In member function `T& Vec<T>:perator[](int)':
y.cpp:14: error: there are no arguments to `at' that depend on a
template parameter, so a declaration of `at' must be available
However under VC++ Express Edition 2005, it compiles well without any
warning or error.
Kindly explain what is wrong with the above program and help me in
fixing the compilation error with g++ under Linux
#include <iostream>
#include <string>
#include <vector>
using namespace std;
template<class T> class Vec : public vector<T>
{
public:
Vec() : vector<T>() { }
Vec(int s) : vector<T>(s) { }
T& operator[] (int i) { return at(i); }
};
int main()
{
Vec<string> s(3);
return 0;
}
Suppose this program is named as y.cpp
When this program is compiled under Redhat Enterprise Linux
Workstation, as
g++ -std=c++98 -pedantic -Wall -Wextra y.cpp
I am getting the following compilation error:
y.cpp: In member function `T& Vec<T>:perator[](int)':
y.cpp:14: error: there are no arguments to `at' that depend on a
template parameter, so a declaration of `at' must be available
However under VC++ Express Edition 2005, it compiles well without any
warning or error.
Kindly explain what is wrong with the above program and help me in
fixing the compilation error with g++ under Linux