|
-
Mar 13th, 2002, 08:56 PM
#1
Thread Starter
Fanatic Member
ok, im just starting to understand polymorphism, its a cool subject but im getting a few errors and im totally lost now
Code:
#include<iostream>
#include<vector>
using namespace std;
/////////////////////////////////////////////////////
class MenuBase{};
/////////////////////////////////////////////////////
template<class InputType, class ReturnType, class ParamType1, class ParamType2>
class MenuItem : public MenuBase
{
public:
InputType GetInput(void){return m_Input;}
void SetInput(InputType Input){m_Input = Input;}
private:
InputType m_Input;
};
/////////////////////////////////////////////////////
class Menu
{
public:
Menu(vector<MenuBase*> items)
:m_items(items)
{}
int GetSize(void){return m_items.size();}
private:
vector<MenuBase*> m_items;
};
/////////////////////////////////////////////////////
int main()
{
vector<MenuBase*> menu(3);
MenuItem<int, int, char, int> menuitem1;
menuitem1.SetInput(100);
menu[0] = menuitem1;
MenuItem<char, int, int, long> menuitem2;
menuitem2.SetInput('A');
menu[1] = menuitem2;
MenuItem<bool, bool, int, char> menuitem3;
menuitem3.SetInput(true);
menu[2] = menuitem3;
Menu theMenu(menu);
cout << theMenu.GetSize() << endl;
return 0;
}
i get these 3 errors
C:\Dan's Stuff\School\C++ Projects\CS4\Polymorphism\TempMenu.cpp(46) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class MenuItem<int,int,char,int>' (or there is no acceptable conversion)
C:\Dan's Stuff\School\C++ Projects\CS4\Polymorphism\TempMenu.cpp(50) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class MenuItem<char,int,int,long>' (or there is no acceptable conversion)
C:\Dan's Stuff\School\C++ Projects\CS4\Polymorphism\TempMenu.cpp(54) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class MenuItem<bool,bool,int,char>' (or there is no acceptable conversion)
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|