locked
namespace nonsense

    Question

  • I have a class, it needs to be in a namespace...  So, I put this REF class in a namespace.  Then, I get this:

    Error 79 error C2757: 'TheTeapotIsFishing' : a symbol with this name already exists and therefore this name cannot be used as a namespace name (BonusBanana.cpp) 

    Never mind the strange namespace name (I got so aggravated, I tried something that I know can't be ambiguous).

    Behavior.h

    #ifndef BEHAVIOR_H
    #define BEHAVIOR_H
    
    #include "IActor.h"
    
    namespace TheTeapotIsFishing
    {
    	ref class Behavior
    	{
    	internal:
    		Behavior(void);	
    		virtual void Enter();
    		virtual void Exit();
    		virtual void Execute();
    		virtual void Execute(float timeTotal, float timeDelta);
    	};
    }
    
    #endif


    Behavior.cpp

    #include "Behavior.h"
    
    TheTeapotIsFishing::Behavior::Behavior()
    {
    }
    
    void TheTeapotIsFishing::Behavior::Enter()
    {
    }
    
    void TheTeapotIsFishing::Behavior::Exit()
    {
    }
    
    void TheTeapotIsFishing::Behavior::Execute()
    {
        Execute(0.0f, 0.0f);
    }
    
    void TheTeapotIsFishing::Behavior::Execute(float timeTotal, float timeDelta)
    {
    }

    Before this, I had strange ambiguous problems in other files that tried to use "Behavior.h", even though I would put using namespace "TheTeapotIsFishing".

    Any help, I'm exhausted with C++?



    • Edited by DualOpAmp Tuesday, October 09, 2012 2:42 PM
    Tuesday, October 09, 2012 2:41 PM

Answers

  • Your code above doesn't repro the problem without the details on what's in IActor.h.

    PS: #pragma once is your friend to avoid having to do that silly #ifndef BEHAVIOR_H
    #define BEHAVIOR_H / #endif pattern.

    • Marked as answer by DualOpAmp Wednesday, October 10, 2012 10:33 PM
    Tuesday, October 09, 2012 7:04 PM

All replies

  • Your code above doesn't repro the problem without the details on what's in IActor.h.

    PS: #pragma once is your friend to avoid having to do that silly #ifndef BEHAVIOR_H
    #define BEHAVIOR_H / #endif pattern.

    • Marked as answer by DualOpAmp Wednesday, October 10, 2012 10:33 PM
    Tuesday, October 09, 2012 7:04 PM
  • ref class TheTeapotIsFishing::Behavior;
    
    namespace TheTeapotIsFishing
    {
    	public interface class IActor
    	{
    	public:
    		void ChangeBehavior(TheTeapotIsFishing::Behavior^ behavior);
    	};
    }


    Despite the fact that IActor has no header guards (which I just noticed) I just fixed it and I still get the same errors.

    Edit: I don't know, I like the header guards, there's something more elegant about them.  Also, they're not compiler-specific.

    • Edited by DualOpAmp Tuesday, October 09, 2012 9:27 PM
    Tuesday, October 09, 2012 7:17 PM
  • Okay, I finally found the problem and sure enough it was in IActor. My problem had to with namespaces and forward declarations.  Apparently, when using a forward declaration in a namespace, the syntax needs to be like this:

    namespace SSSEngine
    {
    	ref class Behavior;
    }

    Wednesday, October 10, 2012 10:33 PM
  • "Also, they're not compiler-specific"

    Sure, but C++/CX code is already compiler-specific...

    Thursday, October 11, 2012 8:26 PM
  • True.
    Thursday, October 11, 2012 9:14 PM