Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Cyclic dependency in header file

Cyclic dependency in header file

Scheduled Pinned Locked Moved C / C++ / MFC
help
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pandit84
    wrote on last edited by
    #1

    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"

    N C S 3 Replies Last reply
    0
    • P pandit84

      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"

      N Offline
      N Offline
      Niklas L
      wrote on last edited by
      #2

      For starters, verify you have include guards in your header files.

      #ifndef _MANAGER_H_INCLUDED
      #define _MANAGER_H_INCLUDED
      // your code here
      #endif

      or

      #pragma once
      // your code here

      Also check that you don't include another header, that in turn includes a file defining a Manager class.

      home

      1 Reply Last reply
      0
      • P pandit84

        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"

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        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]

        1 Reply Last reply
        0
        • P pandit84

          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"

          S Offline
          S Offline
          Stefan_Lang
          wrote on last edited by
          #4

          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.

          P 1 Reply Last reply
          0
          • S Stefan_Lang

            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.

            P Offline
            P Offline
            pandit84
            wrote on last edited by
            #5

            Thanks a lot for your reply. Solved , it was a namespace clash. Thanks stefen

            S 1 Reply Last reply
            0
            • P pandit84

              Thanks a lot for your reply. Solved , it was a namespace clash. Thanks stefen

              S Offline
              S Offline
              Stefan_Lang
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups