Should I be able to forward declare something from a namespace different
from the current one? For example the following code compiles:
//testdriver.hpp
#ifndef TESTDRIVER_HPP
#define TESTDRIVER_HPP
#include <ostream>
namespace ns_testdriver{
using std::ostream;
class Testdriver{
public:
Testdriver(){}
virtual ~Testdriver(){}
virtual void runTest(ostream & out);
};
}
#endif
/*************** *************** */
//testdriver.cpp
#include "testdriver.hpp "
namespace ns_testdriver{
void Testdriver::run Test(ostream& out){
out << "This is ns_testdriver:: Testdriver";
}
}
When I tried to forward declare std::ostream in testdriver.hpp I couldn't
figure out a way that would compile. Is this the wrong thing to try to do,
or am I just screwing it up?
The following code is one example of the different things I've tried. It
results in "error: `ostream' is already declared in this scope":
//testdriver.hpp
#ifndef TESTDRIVER_H
#define TESTDRIVER_H
namespace ns_testdriver{
using namespace std;
class ostream;
class Testdriver{
public:
Testdriver(){}
virtual ~Testdriver(){}
virtual void runTest(ostream & out);
};
}
#endif
/*************** *************** */
//testdriver.cpp
#include "testdriver.hpp "
#include <ostream>
namespace ns_testdriver{
using std::ostream;
void Testdriver::run Test(ostream& out){
out << "This is ns_testdriver:: Testdriver";
}
}
--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
from the current one? For example the following code compiles:
//testdriver.hpp
#ifndef TESTDRIVER_HPP
#define TESTDRIVER_HPP
#include <ostream>
namespace ns_testdriver{
using std::ostream;
class Testdriver{
public:
Testdriver(){}
virtual ~Testdriver(){}
virtual void runTest(ostream & out);
};
}
#endif
/*************** *************** */
//testdriver.cpp
#include "testdriver.hpp "
namespace ns_testdriver{
void Testdriver::run Test(ostream& out){
out << "This is ns_testdriver:: Testdriver";
}
}
When I tried to forward declare std::ostream in testdriver.hpp I couldn't
figure out a way that would compile. Is this the wrong thing to try to do,
or am I just screwing it up?
The following code is one example of the different things I've tried. It
results in "error: `ostream' is already declared in this scope":
//testdriver.hpp
#ifndef TESTDRIVER_H
#define TESTDRIVER_H
namespace ns_testdriver{
using namespace std;
class ostream;
class Testdriver{
public:
Testdriver(){}
virtual ~Testdriver(){}
virtual void runTest(ostream & out);
};
}
#endif
/*************** *************** */
//testdriver.cpp
#include "testdriver.hpp "
#include <ostream>
namespace ns_testdriver{
using std::ostream;
void Testdriver::run Test(ostream& out){
out << "This is ns_testdriver:: Testdriver";
}
}
--
STH
Hatton's Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
Comment