Using vector of references to a template class in the same template class.

Discussion in 'C++' started by Jonathan Bartlett, Feb 8, 2005.

  1. Re: Using vector of references to a template class in the same templateclass.

    wrote:
    > I am trying to create a template class, which would store a vector of
    > references to objects of the same class. Like:
    >
    > template<class _core_t>
    > class Neuron
    > {
    > ///snipped
    >
    > private:
    > vector<Neuron<_core_t>*> _neighbors;
    > }
    >
    > But the compiler (MSVS8) says "missing storage class or type
    > specifiers" when it tries to compile vector definition line.
    >
    > Where's the problem? Thanks!
    >


    Works fine with GCC. Probably a Microsoft problem. Or it could be your
    missing semicolon at the end of the class definition. Or you could be
    forgetting to #include <vector> or you could be forgetting to "using
    namespace std;"

    Jon
    ----
    Learn to program using Linux assembly language
    http://www.cafeshops.com/bartlettpublish.8640017
     
    Jonathan Bartlett, Feb 8, 2005
    #1
    1. Advertising

  2. Jonathan Bartlett

    Guest

    I am trying to create a template class, which would store a vector of
    references to objects of the same class. Like:

    template<class _core_t>
    class Neuron
    {
    ///snipped

    private:
    vector<Neuron<_core_t>*> _neighbors;
    }

    But the compiler (MSVS8) says "missing storage class or type
    specifiers" when it tries to compile vector definition line.

    Where's the problem? Thanks!
     
    , Feb 8, 2005
    #2
    1. Advertising

  3. Re: Using vector of references to a template class in the same templateclass.

    wrote:
    > I am trying to create a template class, which would store a vector of
    > references to objects of the same class.


    Actually it's a vector of pointers.

    > Like:
    >
    > template<class _core_t>
    > class Neuron
    > {
    > ///snipped
    >
    > private:
    > vector<Neuron<_core_t>*> _neighbors;
    > }

    ;
    >
    > But the compiler (MSVS8) says "missing storage class or type
    > specifiers" when it tries to compile vector definition line.
    >
    > Where's the problem? Thanks!


    Did you include <vector> ? Did you write "using std::vector"? Does this
    code:

    #include <vector>
    template<class X> class A {
    std::vector<A<X>*> v;
    public:
    A() {}
    };
    int main() {
    A<int> ai;
    }

    compile for you? If not, the problem is in Redmond, Washington state,
    U.S.A. But that's one you cannot fix. If it compiles (as it should),
    the problem elsewhere in your code.

    Victor
     
    Victor Bazarov, Feb 8, 2005
    #3
  4. Jonathan Bartlett

    Guest

    Sorry, it works... I just didn't mention "using namespace std;" at the
    top to include vector definition.
     
    , Feb 8, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roger Leigh
    Replies:
    8
    Views:
    461
    Karl Heinz Buchegger
    Nov 17, 2003
  2. pmatos
    Replies:
    6
    Views:
    24,020
  3. Replies:
    8
    Views:
    1,983
    Csaba
    Feb 18, 2006
  4. Javier
    Replies:
    2
    Views:
    600
    James Kanze
    Sep 4, 2007
  5. Rushikesh Joshi
    Replies:
    0
    Views:
    386
    Rushikesh Joshi
    Jul 10, 2004
Loading...

Share This Page