Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

sp00nfed

Problem with reducing a inherited class back to the base class

This topic is 6012 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've got a base class "FileLoader", and the class "BMPLoader" inherits from it. Later "FileManager" uses the stl vector to keep track of files loaded, however I get a error message: d:\dev\files\files.cpp(12) : error C2243: 'type cast' : conversion from 'class FileLoaders::BMPLoader *' to 'const class FileLoaders::FileLoader &' exists, but is inaccessible Please not that "FileLoaders" is in fact the namespace I'm using for these classes. // files.h
  
/*
	File loading support (experimental) 
*/

#ifndef FILES_H__
#define FILES_H__

#include <vector>
#include <iostream>
#include <assert.h>

using namespace std;


namespace FileLoaders 
{
	enum filetypes {
		file_bmp,
		file_autodetect // autodetect file type based on it's extension

	};
	
	class FileLoader 
	{
		public:
			FileLoader() {};
			FileLoader(const char *filename) { Load(filename); }
			~FileLoader() { Unload(); }
			bool Load(const char *filename) { return false; };
			bool Unload() { return false; };			
	};

	class BMPLoader : FileLoader
	{
		private:	
		public:
			BMPLoader() {};
			BMPLoader(const char *filename) { Load(filename); }
			bool Load(const char *filename) { return false; };
			bool Unload() { return false; };			
	};

	class FileManager
	{
		private:
			vector<FileLoader> Files;
		public:
			bool LoadFile(char *filename, int type);
	};

}

#endif // FILES_H__

  
// files.cpp
  

#include "files.h"

using namespace FileLoaders;

bool FileManager::LoadFile(char *filename, int type)
{
	switch (type) {
		case file_bmp:
			cout << "LoadFile: Loading a bmp file" << endl;			
			Files.push_back(BMPLoader(filename)); // error occurs here

			break;
		case file_autodetect:
			cout << "LoadFile: Autodetecting file type" << endl;
			break;
		default:
			cout << "LoadFile: Error loading file: unknown file type" << endl;
	}

	return false;
}
  
// filetest.cpp
  
// filestest.cpp


#include <stdio.h>
#include "files.h"

using namespace FileLoaders;

int main()
{
	FileManager fm;
	
	fm.LoadFile("bleh.bmp", file_autodetect);
	return 0;
}
  
Anyone have an ideas? I'm totally confused, this is the first time I've used inheritance.. and I'm not really too sure about it. I think I have the concepts right, but I'm just getting my implementation wrong. -sp00nfed (Edit: fixed your source tags - Kylotan.) Edited by - Kylotan on February 4, 2002 8:20:48 AM

Share this post


Link to post
Share on other sites
Advertisement
I see the problem now.

Moving it back and storing it as the base class in a vector list means that I would not know what kind of FileLoader I have in the vector list.

So that would cause problems

Oh well.

Share this post


Link to post
Share on other sites
I''d suggest reading Meyers''s Effective C++

There''s an item on ''never treat arrays polymorphically'' which is the issue here.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!