S
Steven T. Hatton
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:stream;
class Testdriver{
public:
Testdriver(){}
virtual ~Testdriver(){}
virtual void runTest(ostream& out);
};
}
#endif
/*******************************/
//testdriver.cpp
#include "testdriver.hpp"
namespace ns_testdriver{
void Testdriver::runTest(ostream& out){
out << "This is ns_testdriver::Testdriver";
}
}
When I tried to forward declare std:stream 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:stream;
void Testdriver::runTest(ostream& out){
out << "This is ns_testdriver::Testdriver";
}
}
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:stream;
class Testdriver{
public:
Testdriver(){}
virtual ~Testdriver(){}
virtual void runTest(ostream& out);
};
}
#endif
/*******************************/
//testdriver.cpp
#include "testdriver.hpp"
namespace ns_testdriver{
void Testdriver::runTest(ostream& out){
out << "This is ns_testdriver::Testdriver";
}
}
When I tried to forward declare std:stream 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:stream;
void Testdriver::runTest(ostream& out){
out << "This is ns_testdriver::Testdriver";
}
}