1

I have a class template Foo which has a private data member whose data type is std::vector<T> and a public constructor whose argument is used to resize the vector.

template<typename T>
class Foo
{
  private:
  std::vector<T> Vector_;
  
  Foo(){}
  
  public:
  Foo( const int& size )
  {
    Vector_.resize(size);
  }
};

On the other hand, I have another class Bar which has a private data member of Foo<int>.

class Bar
{
  private:
  Foo<int> AFoo(3);
  
  public:
  Bar(){}
};

Finally, I would like to declare a Bar in the main function.

int main( int argc, char* argv[] )
{
  Bar ABar;
  
  return 0;
}

But I got the following error: expected identifier before numeric constant indicated at the character 3 of Foo<int> AFoo(3);.

I am appreciate if anyone knows how to fix this error.

Evg
  • 25,259
  • 5
  • 41
  • 83
Rex Liu
  • 39
  • 1
  • 5

0 Answers0