473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

uninitialized reference member

I am facing the following error:

cpptest-textoutput.h: In constructor âTest::TextOutput::TextOutput(Test::TextOutput::Mo de, std::ostream&)â:
cpptest-textoutput.h:63: error: uninitialized reference member âTest::TextOutput::_streamâ

Code snippet:

/** \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, std::ostream&):mode(_mode),stream(std::cout)
{
}
virtual void finished(int tests, const Time& time);
virtual void suite_start(int tests, const std::string& name);
/// 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, std::ostream&):Mode(_mode),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;
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
//
// ---

/** \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::ostream& 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::ostream& _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

someone out ther:Pls help me out.

Thanks in advance.
Aug 25 '10 #1
7 4368
newb16
687 512MB
If you want to get rid of this error, simply comment out this line:
//std::ostream& _stream;

And you file looks like in have two copies of some other file pasted one after another - class declaration suddenly terminates and copyright header begins.

private:
typedef std::list<Source> ErrorList;
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
//
// ---
Aug 25 '10 #2
Oralloy
985 Expert 512MB
priethe,

In the future, please use code tags, so that we can talk about your code and reference specific line numbers.

I must admit, newb16 is right about your code looking a little confused.

What I see is that you are declaring a nested class TextOutput within the class TextOutput.

Is that what you really intended?

Or do you want to have a class ::Test::TextOutput in addition to a top level class ::TextOutput ?

Why don't you try to sort that out, and then re-post your corrected code with any other difficulties you may be having?

Luck!
Aug 25 '10 #3
oh! am sorry.I had pasted the code twice.

pls look into this :

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::ostream& 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::ostream& _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;
}


also I tried the solution given by newb16.It gives the following errors.

/tmp/cceUiSFX.o: In function `Test::TextOutput::TextOutput(Test::TextOutput::Mo de, std::basic_ostream<char, std::char_traits<char> >&)':
test.cpp:(.text._ZN4Test10TextOutputC1ENS0_4ModeER So[Test::TextOutput::TextOutput(Test::TextOutput::Mod e, std::basic_ostream<char, std::char_traits<char> >&)]+0x1e): undefined reference to `vtable for Test::TextOutput'
/tmp/cceUiSFX.o: In function `Test::TextOutput::~TextOutput()':
test.cpp:(.text._ZN4Test10TextOutputD1Ev[Test::TextOutput::~TextOutput()]+0xe): undefined reference to `vtable for Test::TextOutput'
collect2: ld returned 1 exit status
Aug 26 '10 #4
newb16
687 512MB
Do you compile and link it with cpptest-textoutput.cpp ?
Aug 26 '10 #5
i just compile test.cpp file.already cpptest-textoutput is included as a header file
Aug 26 '10 #6
newb16
687 512MB
vtable for Test::TextOutput may happen if you don't implement virtual methods you declare.
Aug 26 '10 #7
Oralloy
985 Expert 512MB
Here's a little bit on tags, that'll help folks read your code.

Please use them. It really does help.

Anyway, with that last set of errors you posted, it looks like you're not linking your driver with cpptest-textoutput.o

Perhaps you need to compile with something like:
Expand|Select|Wrap|Line Numbers
  1. g++ test.cpp cpptest-textoutput.cpp -o myExecutable
Luck!
Aug 26 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: supachamp | last post by:
Hi everybody, I am having great problems with the following classes. I just can't figure out why I keep getting the error message: Building file: ../edge.cc Invoking: GCC C++ Compiler g++...
8
by: ken.carlino | last post by:
Hi, Can I use Reference type as my class attribute, like this? Or I have to use pointers for class attribute? class B; class A { public: B& _b; };
37
by: Joergen Bech | last post by:
(Slightly religious question): Suppose I have the following class: ---snip--- Public Class MyClass Private _MyVariable As Integer Public Property MyVariable() As Integer Get
8
by: Tim Clacy | last post by:
1) Is this initialising the reference 'u' to the address of the literal '2' or to the address 0x00000002? unsigned const& u = 2; 2) What is the different between the initialisation of 'u'...
5
by: vivekian | last post by:
Hi , Have a class where a private member is a reference member which needs to be initialized when the constructor is called. The compiler rightly will not allow this. Is there some way to...
8
by: Bart Simpson | last post by:
If a class has a member variable that is a reference. What happens to teh class that is being referenced, when the containing class is destroyed? e.g. Class A{ }; Class B { B(const A&...
4
by: Bart Simpson | last post by:
I have a class that has a member that is a const reference: class MyClass { public: MyClass(const AnotherClass& ac); MyClass(const MyClass& mc); MyClass& operator= (const MyClass& mc); ...
3
by: ww | last post by:
I read a couple of books that tells this, but seems not one can explain why is this thanks
6
by: msgurikar | last post by:
Hi, How do i handle reference member variable in assignment operator and copy constructor. class A{ private: int& a; public: A(); ~A();
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.