Tilted Forum Project Discussion Community

Tilted Forum Project Discussion Community (https://thetfp.com/tfp/)
-   Tilted Technology (https://thetfp.com/tfp/tilted-technology/)
-   -   c++ use of class template as an expression? (https://thetfp.com/tfp/tilted-technology/46241-c-use-class-template-expression.html)

strcrssd 02-19-2004 02:50 PM

c++ use of class template as an expression?
 
I'm lost as to what is wrong here, can anyone give me a hand?

Code:

#include <vector>
using namespace std;

template<typename kind>class visVector:public vector<kind>{
    public:
        visVector(int basex, int basey);
        kind operator[](int index);
        kind at(int loc);
        void push_back(kind);
    private:
        int bx, by;
};

template<typename kind>
visVector<kind>::visVector(int basex, int basey){
    bx = basex;
    by = basey;
}
   
template<typename kind>
kind visVector<kind>::operator[](int index){
    return vector::at(index);
}

template<typename kind>
kind visVector<kind>::at(int index){
    return vector::at(index);
}

template<typename kind>
void visVector<kind>::push_back(kind toBeAdded){
    //need to locate where we're pushing onto, then highlight that section
    vector::push_back(toBeAdded)
}

int main(int argc, char* argv){
    visVector<int> v;
    for(int i = 0; i < 10; i++)
        v.push_back(i);
    for(int i = 0; i < v.size(); i++)
        cout << v[i] << ", ";
        cout << endl;
    for(int i = 0; i < v.size(); i++)
        v[i] = v[i] * 10; // Assignment 
    for(int i = 0; i < v.size(); i++)
        cout << v[i] << ", ";
        cout << endl;
}

I'm getting the error code in g++:

Quote:

visVector.cpp: In member function `kind visVector<kind>::operator[](int)':
visVector.cpp:22: error: use of class template `template<class _Tp, class
_Alloc> class std::vector' as expression

I have no idea what this means. Anyone?

Thanks

n0nsensical 02-19-2004 06:38 PM

Re: c++ use of class template as an expression?
 
Quote:

Originally posted by strcrssd
template<typename kind>
kind visVector<kind>::operator[](int index){
return vector::at(index);
}

has to be
return vector<kind>::at(index);


All times are GMT -8. The time now is 05:11 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73