E
E
Elnurhan2020-10-07 12:42:31
C++ / C#
Elnurhan, 2020-10-07 12:42:31

How to use forward declaration?

Hello! I recently learned about forward declaration and a question appeared: I have a Log.h file, with the following "skeleton":

Log.h

class LogCollapserMaker
{
public:
  class LogCollapser
  {
  public:
    LogCollapser(uint32_t estimateCount);
    bool estimated();

  private:
    boost::recursive_mutex			m_collapserMutex;
    const uint32_t					m_estimateCount;
    uint32_t						m_count;
  };

public:
  typedef boost::shared_ptr<LogCollapser> LogCollapserSP;

  LogCollapserSP logCollapser(const std::string& key, uint32_t estimateCount);

private:
  boost::recursive_mutex					m_mutex;
  std::map<std::string, LogCollapserSP>	        m_logCollapserMap;
};


The Log.cpp file contains the entire implementation.
How can I use a forward declaration with such a structure?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maaGames, 2020-10-07
@Elnurhan

ATTENTION! This is a bad example, don't do it!

//fwd
class LogCollapserMaker;

LogCollapserMaker * GetLog(); // в срр реализация функции
// fwd только для того, чтобы объявить эту функцию до объявления класса


class LogCollapserMaker
{
public:
  class LogCollapser
...
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question