Cyclic dependency in header file
-
Hi I have created an interface in interface.h file as below
class Manager ; class IManager { public : virtual void \_\_stdcall fun(Manager\* ptr)=0 ; };
Manager class is declared in another sourceFile.h
#include "interface.h"
class Manager
{
public :
Manager () ;
~Manager () ;
IManager* GetMyManager () ;
IManager* _VarManager ;
};I have provided forward declaration of class Manager in interface.h .When I try to compile my project it fails with an error "Ambigious Class Manager"
-
Hi I have created an interface in interface.h file as below
class Manager ; class IManager { public : virtual void \_\_stdcall fun(Manager\* ptr)=0 ; };
Manager class is declared in another sourceFile.h
#include "interface.h"
class Manager
{
public :
Manager () ;
~Manager () ;
IManager* GetMyManager () ;
IManager* _VarManager ;
};I have provided forward declaration of class Manager in interface.h .When I try to compile my project it fails with an error "Ambigious Class Manager"
For starters, verify you have include guards in your header files.
#ifndef _MANAGER_H_INCLUDED
#define _MANAGER_H_INCLUDED
// your code here
#endifor
#pragma once
// your code hereAlso check that you don't include another header, that in turn includes a file defining a Manager class.
-
Hi I have created an interface in interface.h file as below
class Manager ; class IManager { public : virtual void \_\_stdcall fun(Manager\* ptr)=0 ; };
Manager class is declared in another sourceFile.h
#include "interface.h"
class Manager
{
public :
Manager () ;
~Manager () ;
IManager* GetMyManager () ;
IManager* _VarManager ;
};I have provided forward declaration of class Manager in interface.h .When I try to compile my project it fails with an error "Ambigious Class Manager"
Posted should compile. You should post also the relevant source(s) file. As already suggested you should also guard your header aggainst multiple inclusion. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi I have created an interface in interface.h file as below
class Manager ; class IManager { public : virtual void \_\_stdcall fun(Manager\* ptr)=0 ; };
Manager class is declared in another sourceFile.h
#include "interface.h"
class Manager
{
public :
Manager () ;
~Manager () ;
IManager* GetMyManager () ;
IManager* _VarManager ;
};I have provided forward declaration of class Manager in interface.h .When I try to compile my project it fails with an error "Ambigious Class Manager"
pandit84 wrote:
"Ambigious Class Manager"
Could you quote the precise text of that message please? The error number might help, too. My first guess is that the error is not related to your definition of Manager and IManager at all. More likely, either you have a clash of namespaces (e. g. you might have multiple classes called Manager in different namespaces; maybe even a forward declaration outside the correct namespace could cause it), or you derived classes from Manager using multiple inheritance. The latter can be a problem if you inherit Manager via multiple paths, causing inheritance ambiguity. See here (under "Pointer conversions") for an example of the inheritance ambiguity.
-
pandit84 wrote:
"Ambigious Class Manager"
Could you quote the precise text of that message please? The error number might help, too. My first guess is that the error is not related to your definition of Manager and IManager at all. More likely, either you have a clash of namespaces (e. g. you might have multiple classes called Manager in different namespaces; maybe even a forward declaration outside the correct namespace could cause it), or you derived classes from Manager using multiple inheritance. The latter can be a problem if you inherit Manager via multiple paths, causing inheritance ambiguity. See here (under "Pointer conversions") for an example of the inheritance ambiguity.
-
Yay, a stab in the dark, and a hit! :cool: It does confirm my general tactic of actually reading the error message before bothering to look at the code. :-D