Re: Circular include problem
Is this a circular class reference problem - both classes referring to each other?
If yes, then you need to forward declare one class before it is used in the other. Note that if this is the problem and you do this, you can only access the members of the forward declared class in the other via pointers - other you get an error message re incomplete class.
Code:
struct Fclass;
struct Myclass {
Fclass* fclas {};
Myclass() {}
Myclass(Fclass* fc) : fclas(fc) {}
};
struct Fclass {
Myclass mclas;
};
int main()
{
Fclass fc;
Myclass mc(&fc);
}
If this isn't the problem, can you provide a simple one file compilable example.
Re: Circular include problem
I have the class DBTestConnection:
Code:
#include "SU_ORADB_imp.h"
class DBTestConnection final : public Connection
{
private:
SU_ORADB_imp* imp_{ nullptr };
...
error:
Code:
dbtestconnection.h(10): error C2143: syntax error: missing ';' before '*'
of course, I tried to declare only this class:
Code:
class SU_ORADB_imp;
class DBTestConnection final : public Connection
{
private:
SU_ORADB_imp* imp_{ nullptr };
...
the I got
Code:
dbtestconnection.h(27): error C2027: use of undefined type 'SU_ORADB_imp'
I mean, when I am trying to use this memeber (imp_). Seems it is an endless loop around the tale.
Re: Circular include problem
How and where are you using imp_ ? Can you provide a minimal test compilable program that shows the problem.
Re: Circular include problem
A quick attempt to fix your problem did not lead to success.
I would try the following:
- disable the precompiled header
- in each file that is reported to have errors: comment out all includes, and try to get it to compile with forward declarations
- move all implementation from .h to .cpp files
- move the definition of the factory to a single header file
1 Attachment(s)
Re: Circular include problem
I have simplified the sample project, and after few changes, I left just one point error:
Code:
connectionfactory.h(8): error C2065: 'DBTestConnection': undeclared identifier
connectionfactory.h(9): error C2923: 'ConnectionPoolFactory': 'DBTestConnection' is not a valid template type argument for parameter 'T'
connectionfactory.h(23): error C2913: explicit specialization; 'ConnectionPoolFactory' is not a specialization of a class template
and that error fire here:
Code:
#pragma once
#include "connection.h"
#include "pool.h"
#include "DBTestConnection.h"
template <>
class ConnectionPoolFactory<DBTestConnection> // <--- error
{
public:
static std::unique_ptr<ConnectionPool> create(const std::uint16_t& num_connections)
{
std::vector<std::unique_ptr<Connection>> connections;
for (std::uint16_t k = 0; k < num_connections; ++k)
{
connections.emplace_back(std::unique_ptr<DBTestConnection>(new DBTestConnection{}));
}
return std::unique_ptr<ConnectionPool>(new ConnectionPool{ std::move(connections) });
}
private:
ConnectionPoolFactory() = default;
};
Re: Circular include problem
Provide a minimal test compilable program that shows the problem - one .cpp file of at most a couple of dozen lines (no .h files etc) that can be pasted here and copy/pasted easily into the compiler. Providing a zip file consisting of multiple .h/.cpp files within a project isn't really going to help.
Re: Circular include problem
I agree with 2kaud.
The posted zip projects are two complicated for investigations since there is a lot of relationships between classes, headers and sources files (plus a lot of or, I'd say, too many #includes!).
Re: Circular include problem
Try this DBTestConnection.h
Code:
#pragma once
#include "TestConnection.h"
#include "connection.h"
//#include "SU_ORADB_imp.h"
#include "oci.h"
//#include "ConnectionFactory.h"
class SU_ORADB_imp;
class DBTestConnection final : public Connection
{
private:
SU_ORADB_imp* imp_{ nullptr };
bool m_connected = false;
// methods
DBTestConnection();
// friend class
//friend ConnectionPoolFactory<DBTestConnection>;
template <typename T>
friend class ConnectionPoolFactory;// <DBTestConnection>
public:
void disconnect() override;
bool connect() override;
void do_something();
~DBTestConnection() override;
OCISvcCtx* GetServerContext();
};
The problem is
a) in DBTestConnection.h you include ConnectionFactory.h, which then needs to know class DBTestConnection. But the compiler has not seen a declaration of it at that point.
b) your friend declaration is incorrect, but the compiler didn't even come to that point.
Re: Circular include problem
Thank you a lot Richard !