Class template problem: template argument 1 is invalid

Discussion in 'C++' started by jtravs@gmail.com, Sep 7, 2012.

  1. Guest

    Hi all, I have a problem with a class template. I want the private data in a class to be a vector of vectors of some kind of numeric type, i.e:

    std::vector<std::vector<double> >
    std::vector<std::vector<std::complex<double> > >

    But I want the type of vector (I'm using a library of third party vectors along with stl vectors), and the element type to be templated. I tried template templates but now I don think that is the solution to my problem. A highly simplified example is:

    #include <complex>
    #include <vector>
    template<typename T>
    class Fred {
    std::vector<T> data_;
    };
    int main(){
    Fred<std::vector<double> > works;
    //Fred<std::vector<std::complex<double> > doesnt_work;
    return 0;
    }

    As shown it compiles fine, but if I uncomment the second line in main, I get the error (g++ 4.6):

    error: template argument 1 is invalid

    Why do I get this error? And does anyone have a suggested fix?

    Thanks,
    John
    , Sep 7, 2012
    #1
    1. Advertising

  2. Guest

    >
    > Why do I get this error? And does anyone have a suggested fix?
    >


    OK, this was solved on stack overflow: I missed a > in the second line! Yes, I'm stupid! Though the error message is a little useless.
    , Sep 7, 2012
    #2
    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. Matthias
    Replies:
    10
    Views:
    721
    Bogdan Sintoma
    Jan 28, 2005
  2. Java Guy
    Replies:
    1
    Views:
    680
    Manish Pandit
    Oct 15, 2006
  3. nw
    Replies:
    0
    Views:
    312
  4. nguillot
    Replies:
    5
    Views:
    530
  5. Java Guy
    Replies:
    1
    Views:
    309
Loading...

Share This Page