Thread: Please help me with the MIL and classes

  1. #1
    Terrance11
    Guest

    Question Please help me with the MIL and classes

    Code:
    /*
    	Terrance Lynch
    	c++ practice with classes
    	November 23, 2002
    */
    
    #include <iostream>
    #include <string>
    #include <sstream>
    #include <strstream>
    using namespace std;
    
    class CStandardAllocator
    {
    	class CStandardAllocator()
    	{
    		cout << 16 << endl;
    	}
    
    };
    
    template<class T, class alloc>
    class CMCVectorImp : public alloc
    {
    public:
    	CMCVectorImp(int sz, int x) : alloc()
    	{
    		cout << sz * x << endl;
    	}
    
    
    };
    
    template<class Vect, class T, class alloc>
    class cBagAsVectorImp : public Data
    {
    public:
    	cBagAsVectorImp(int sz) : Data(sz,1){}
    protected:
    	Vect Data;
    };
    
    
    template <class T, class alloc>
    class cBagAsVector : public cBagAsVectorImp<CMCVectorImp<T,alloc>, T, alloc>
    {
    public:
    	cBagAsVector(int sz) : cBagAsVectorImp<CMCVectorImp<T,alloc>, T, alloc>(sz)
    	{
    		cout << sz << endl;
    	}
    };
    
    template <class T>
    class cBag : public cBagAsVector<T, CStandardAllocator>
    {
    public:
    	cBag(int sz):cBagAsVector<T, CStandardAllocator>(sz){}
    };
    
    
    
    int main()
    {
    	int dBagSize = 4;
    	cBag<double> dBag(dBagSize);
    
    	return 0;
    
    }
    Two compiler errors, it says it doesn't recognize the Data as a base class.

    Please help,
    Thanks,
    Terrance

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    >>Two compiler errors, it says it doesn't recognize the Data as a base class.

    I might have been struck blind, but I cant see Data defined either!

    You have "Vect Data;" as a nested member......but you cant simply use this to inherit from

    Also;

    Code:
    class CStandardAllocator
    {
    class CStandardAllocator()
    {
    cout << 16 << endl;
    }
    
    };
    Assuming you want a constructor....you dont begin the constructor with the class keyword....if you do the compiler thinks it has a nested class...and then spews because the inner class has the same name and doesnt end its declaration with ';'

    What are you trying to achieve? We might be able to give you some ideas

  3. #3
    Terrance11
    Guest
    Thank you. I mistakenly put the word "class" in front of the constructor.

    Sorry, didn't proof read my own code very well

  4. #4
    CIS and business major
    Join Date
    Aug 2002
    Posts
    287
    Originally posted by Terrance11
    Thank you. I mistakenly put the word "class" in front of the constructor.

    Sorry, didn't proof read my own code very well

    btw, I'm not that lazy. I did this on my school's computer, and wanted it to compile before they closed up.

    Thanks.

Popular pages Recent additions subscribe to a feed