C++ Nested Class (Solved)

Started by
1 comment, last by cgrunewald 16 years, 1 month ago
Given the following code:
 
template <class T> 
class A { 
 private: 
 
  class B {
  public: 
    int foo; 
    void bar();
  }; 
 
  B barbar(); 
 
}; 
 
template <class T> 
A<T>::B A<T>::barbar() {
  B  b;
  return b; 
} 
 
 
int main() { 
 
} 
 

I get the compile error: rac3:~/420/420project_part1: g++ test.c test.c:17: error: expected constructor, destructor, or type conversion before 'A' Does anyone have any idea why? As far as I know, this is the proper syntax for declaring a method for a template class. Thanks, Calvin
Advertisement
Try:
template <class T> typename A<T>::B A<T>::barbar() {  typename A<T>::B b;  return b; } 
Thank you.

That worked!

This topic is closed to new replies.

Advertisement