Understanding the following code

This is more a matter of syntax.

Parameter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#define Prm (*ParamLoader::Instance())


class ParamLoader : public iniFileLoaderBase
{
private:
  
    ParamLoader():iniFileLoaderBase("params.ini")
  {
   
    MinDetectionBoxLength     = GetNextParameterFloat();

  }

public:

  static ParamLoader * Instance();

  double MinDetectionBoxLength;


Parameter.cpp
1
2
3
4
5
6
7
Vector2D SteeringBehavior::ObstacleAvoidance(const std::vector<BaseGameEntity*>& obstacles)
{
  
  m_dDBoxLength = Prm.MinDetectionBoxLength +    //<--- How to do this?
                  (m_pVehicle->Speed()/m_pVehicle->MaxSpeed()) *
                  Prm.MinDetectionBoxLength;



My problem is with this part Prm.MinDetectionBoxLength . I have never seen this before in my life, and I was wondering how one accomplishes this. I tried doing it myself, and I got the following error. No suitable conversion exist between "Foo" to "double".

Here is my source

Foo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef FOO_H_
#define FOO_H_

#define Prm (*Foo::getInstance());

class Foo
{
private:
	Foo()
        {
	    mForce = 0.2;
	
	}

public:
	static Foo * getInstance();
	double mForce;
	
};

#endif



Foo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "Foo.h"


Foo * Foo::getInstance()
{
  static Foo instance;

  return &instance;
}

void Foo::showMessage()
{
   double num = Prm.mForce;   //<-- Error

}


I tried to implement the gist of what I saw. I don't know what I'm doing wrong. am I forgetting something?
1
2
// #define Prm (*Foo::getInstance());
#define Prm (*Foo::getInstance()) // no semicolon at the end 


Don't torture yourself; use reference semantics. (If you really must have a singleton.)
See: http://www.cplusplus.com/forum/beginner/152735/
Wow, that was easy. You've been a huge help JLBorges and I appreciate it.
Topic archived. No new replies allowed.