Currently got a weird looking problem with fstream.
1>C:\Program Files\Microsoft Visual Studio 8\VC\include\fstream(675) : error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> C:\Program Files\Microsoft Visual Studio 8\VC\include\ios(151) : see declaration of 'std::basic_ios<_Elem,_Traits>::basic_ios'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> This diagnostic occurred in the compiler generated function 'std::basic_ifstream<_Elem,_Traits>::basic_ifstream(const std::basic_ifstream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
The class header "Unit.h":
#pragma once
#include <iostream>
#include <fstream>
#include <cmath>
#include <vector>
#include "..\Vectors.h"
#include "BulletManager.h"
using namespace std;
struct sUnitInfo
{
int Health;
unsigned int Speed;
unsigned int Power;
unsigned short UnitType;
double VisibleRange;
double FiringRange;
double RateOfFire;
};
class CUnit
{
public:
CUnit(unsigned int UnitID, CBulletManager *inBulletManager);
~CUnit(void);
void Initialise(sUnitInfo inInfo);
unsigned int GetID() { return m_ID; }
unsigned short GetType() { return m_Type; }
CVector2d GetPosition();// return CVector2d(m_RealX, m_RealY); } //m_Position; }
#ifdef _DEBUG
double GetRealX() { return m_RealX; }
double GetRealY() { return m_RealY; }
#endif
double GetShootingRange() { return m_FiringRange; }
double GetViewingRange() { return m_VisibleRange; }
double GetFirepower() { return m_Power; }
bool InflictDamage(double Amount);
void Shoot(CVector2d TargetPosition);
void SetRoute(vector<CVector2i>* Route);
void SetPosition(CVector2d inPosition);
CVector2i NextDestination() { return m_Route[0]; }
void Update(double inFrameTime);
private:
void Move();
void Animate(){ return; }
void Draw(){ return; }
bool Initialised;
unsigned int m_ID;
unsigned int m_Power;
unsigned int m_Speed;
double m_Health;
unsigned int m_TargetID;
unsigned short m_Type;
unsigned short m_Formation;
double m_VisibleRange;
double m_FiringRange;
double m_RateOfFire;
double m_FireTimer;
double m_FrameTime;
double m_RealX;
double m_RealY;
CVector2d m_Position;
vector<CVector2i> m_Route;
bool m_isEnemy;
bool m_isFiring;
bool m_HasRoute;
CBulletManager* m_BulletManager;
ifstream UnitLog;
};
I would have edited this down a little but I'm unsure how it would affect the declaration of fstream.
This isn't the only class where I'm using the fstream object. I have it declared exactly the same in 3 other classes.
Specifically in "FileReader.h"
#pragma once
#include <iostream>
#include <fstream>
#include <vector>
#include "MapData.h"
#include "Unit.h"
using namespace std;
typedef vector<unsigned short> MapY;
typedef vector<MapY> Map;
class CFileReader
{
public:
CFileReader(void);
~CFileReader(void);
bool LoadMap(char* Mapname, CMapData* MapData);
bool SaveMap(char* Mapname, CMapData* MapData);
bool LoadUnitInfo(vector<sUnitInfo>* UnitInfo);
// bool SaveUnit();
private:
fstream Logger;
};
Which works perfectly.
fstream& UnitLog; doesn't work
fstream* UnitLog; doesn't work
ifstream UnitLog; (or any variation */&) doesn't work
ofstream UnitLog; (or any variation */&) doesn't work
I have tried creating a completely empty class and including it there instead with "Logger.h"
#pragma once
#include <iostream>
#include <fstream>
#using namespace std;
class CLogger
{
public:
CLogger();
~CLogger();
private:
fstream Log;
};
Which also fails.
So I'm at a loss now. I don't know what is causing the error. Any help is greatly appreciated and urgently required (as this is my Final Year Project for University) >.<
[Edited by - Ehrys on March 7, 2007 8:29:55 AM]