Original Post
Maybe you're familiar with this but I'm not.Untill now I never saw a friend function.
Here's the code:
[source lang="cpp"]#ifndef TEXTUREMGR_H
#define TEXTUREMGR_H
#include "d3dUtil.h"
#include
#include
class TextureMgr
{
public:
friend TextureMgr& GetTextureMgr();
typedef std::vector StringVector;
void init(ID3D10Device* device);
// for debug
void dumpInfo()const;
ID3D10ShaderResourceView* getRandomTex();
ID3D10ShaderResourceView* createTex(std::wstring filename);
ID3D10ShaderResourceView* createTexArray(
std::wstring arrayName,
const std::vector& filenames);
// .dds files can store cube textures in one file
ID3D10ShaderResourceView* createCubeTex(std::wstring filename);
private:
TextureMgr();
TextureMgr(const TextureMgr& rhs);
TextureMgr& operator=(const TextureMgr& rhs);
~TextureMgr();
void buildRandomTex();
private:
ID3D10Device* md3dDevice;
StringVector mTextureNames;
std::vector mTextureRVs;
ID3D10ShaderResourceView* mRandomTexRV;
};
TextureMgr& GetTextureMgr();
#endif // TEXTUREMGR_H[/source]
[source lang="cpp"]TextureMgr& GetTextureMgr()
{
static TextureMgr tm;
return tm;
}[/source]
In my book it says I can only have 1 texture manager.So a friend function gets acces to everything in a class,and that GetTextureMgr() also returns a TextureMgr type of object.
But why do we need an adress? friend TextureMgr& GetTextureMgr();
Can someone give me a good explanation?
Here's the code:
[source lang="cpp"]#ifndef TEXTUREMGR_H
#define TEXTUREMGR_H
#include "d3dUtil.h"
#include
#include
class TextureMgr
{
public:
friend TextureMgr& GetTextureMgr();
typedef std::vector
void init(ID3D10Device* device);
// for debug
void dumpInfo()const;
ID3D10ShaderResourceView* getRandomTex();
ID3D10ShaderResourceView* createTex(std::wstring filename);
ID3D10ShaderResourceView* createTexArray(
std::wstring arrayName,
const std::vector
// .dds files can store cube textures in one file
ID3D10ShaderResourceView* createCubeTex(std::wstring filename);
private:
TextureMgr();
TextureMgr(const TextureMgr& rhs);
TextureMgr& operator=(const TextureMgr& rhs);
~TextureMgr();
void buildRandomTex();
private:
ID3D10Device* md3dDevice;
StringVector mTextureNames;
std::vector
ID3D10ShaderResourceView* mRandomTexRV;
};
TextureMgr& GetTextureMgr();
#endif // TEXTUREMGR_H[/source]
[source lang="cpp"]TextureMgr& GetTextureMgr()
{
static TextureMgr tm;
return tm;
}[/source]
In my book it says I can only have 1 texture manager.So a friend function gets acces to everything in a class,and that GetTextureMgr() also returns a TextureMgr type of object.
But why do we need an adress? friend TextureMgr& GetTextureMgr();
Can someone give me a good explanation?