uninitialized reference member
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: uninitialized reference member

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Posts
    1

    uninitialized reference member

    Hi,

    I am getting the following error message:

    cpptest-textoutput.h: In constructor ‚Test::TextOutput::TextOutput(Test::TextOutput::Mode, std:stream&)‚:
    cpptest-textoutput.h:63: error: uninitialized reference member ‚Test::TextOutput::_stream‚



    This is a header file which I am including in my source file test.cpp.

    cpptest-textoutput.h
    -----------------------

    /** \file */

    #ifndef CPPTEST_TEXTOUTPUT_H
    #define CPPTEST_TEXTOUTPUT_H

    #include <iostream>
    #include <list>

    #include "cpptest-source.h"
    #include "cpptest-output.h"

    namespace Test
    {
    /// \brief Text output handler that outputs to the a stream.
    ///
    /// %Test suite output handler that writes its information as text to a
    /// a stream. It it possible to select between two different operational
    /// modes that controls the detail level, see Mode.
    ///
    class TextOutput : public Output
    {
    public:
    /// Output mode.
    ///
    enum Mode
    {
    /// Terse output mode, which only shows the number of correct tests.
    ///
    Terse,

    /// Verbose output mode, which also shows extended assert
    /// information for each test that failed.
    ///
    Verbose
    };

    TextOutput(Mode mode, std:stream& stream = std::cout)
    {
    }
    virtual void finished(int tests, const Time& time);
    virtual void suite_start(int tests, const std::string& name);
    virtual void suite_end(int tests, const std::string& name,
    const Time& time);
    virtual void test_end(const std::string& name, bool ok,
    const Time& time);
    virtual void assertment(const Source& s);

    private:
    typedef std::list<Source> ErrorList;

    Mode _mode;
    std:stream& _stream;
    ErrorList _suite_error_list;
    std::string _suite_name;
    int _suite_errors;
    int _suite_tests;
    int _suite_total_tests;
    int _total_errors;
    };

    } // namespace Test

    #endif // #ifndef CPPTEST_TEXTOUTPUT_H

    source file - test.cpp
    -------------------------
    #include <iostream.h>
    #include "cpptest.h"
    #include "cpptest-suite.h"
    #include "cpptest-output.h"
    #include "cpptest-textoutput.h"

    using namespace std;

    class mytest_test : public Test::Suite
    {
    public:

    mytest_test()
    {
    TEST_ADD(mytest_test::first_test);
    TEST_ADD(mytest_test::sec_test);
    }
    private:
    void first_test();
    void sec_test();
    };

    void mytest_test::first_test()
    {
    cout<<" in first test \n";
    }


    void mytest_test::sec_test()
    {
    cout<<" in sec test \n";
    }


    int main()
    {

    mytest_test mtt;
    Test::TextOutput output(Test::TextOutput::Verbose);
    return mtt.run(output) ? EXIT_SUCCESS : EXIT_FAILURE;
    }


    Pls help me out.Thanks in advance.

  2. #2
    Join Date
    Mar 2002
    Location
    Kent, United Kingdom
    Posts
    399

    Re: uninitialized reference member

    References need to be initialised in the constructor for their containing class.
    your humble savant

  3. #3
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,011

    Re: uninitialized reference member

    - Please use code tags, smilies are not valid C++ code.
    - Your constructor does nothing, not even with the two arguments that are passed.
    - Don't start variable, function or type names with an underscore. That's reserved for the compiler.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center