0

I have following code in C++. Building in Visual studio 2019

class DynamicLogger {

public:
    /**
     * @brief DynamicLogger is singleton class.
     * @return returns instance of dynamic logger which will be used to log messages.
    */

    static DynamicLogger& GetInstance() noexcept {
        //  Static variables with block scope are thread safe which is guaranteed by standard.
        static DynamicLogger instance;
        return instance;
    }
};

class Graph {
public:
    /**
       @brief Graph constructor creates graph with zero vertices.
       @param logger instance which is used to log.
    */
    Graph(DynamicLogger& logger) : m_iNumOfVerticies(0), m_logger(logger) {}

private:
    DynamicLogger& m_logger;
};

In GraphTest.cpp I have following code

I have included graph and logger header files.

#include "../../../GraphExplorers/DynamicLogger/DynamicLogger.h"
#include "../../../GraphExplorers/Graph/Graph.h"

class GraphParsing : public testing::Test {
public:
    vrk::DynamicLogger& logger = vrk::DynamicLogger::GetInstance();
    vrk::Graph graph(logger); **-------------> Error here logger not defined**
};

I put the same code like below it is working

TEST_F(GraphParsing, DISABLED_ReadGraphDataFromFileToConatiners) {
    vrk::Graph graph(logger);
    graph.CreateGraph("..\\..\\..\\..\\InputData\\graph.txt");
    logger.UpdateTraceSettings(false, vrk::LogTraceLevelVal::NoTrace, 0); // disable logs.
    int numberOfVertices = graph.GetNumberOfVertices();
    ASSERT_EQ(graph.GetNumberOfVertices(), 12);
    
}

I am not sure where I am doing mistake. Request to guide me. Thanks

venkysmarty
  • 11,099
  • 25
  • 101
  • 184
  • Please provide a [mre] and the full compiler output. I'd guess it's actually reporting an error for the line above first which then causes `logger` to be undefined – Alan Birtles Dec 30 '20 at 11:16
  • 1
    I think `vrk::Graph graph(logger)` should be `vrk::Graph graph{logger}` or `vrk::Graph graph = vrk::Graph(logger)`. – rveerd Dec 30 '20 at 11:32

0 Answers0