Accessing functions of another file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • randysimes
    New Member
    • Oct 2009
    • 54

    Accessing functions of another file

    In a simple form, I fully understand how to do this.
    Code:
    //foo.h
    class Foo;
    
    Class Foo
    {
      void someFunction(int);
    }
    
    //foo.cpp
    #include <foo.h>
    
    int main()
    {
      Foo foo;
      foo.someFunction(bar);
      ...
      return 0;
    On the other hand, when I have:
    Code:
    //foo.h
    ...
    namespace myStuff
    {
      template typename < X, Y, Z >
      class Foo
      {
        void someFunction(int);
      }
    }; //namespace 
    
    //foo.cpp
    #include <foo.h>
    ...
    
    template typename <X, Y, Z>
    void Foo::someFunction(int)
    {
       //whatever
    }
    
    //bar.cpp
    #include <foo.cpp>
    ...
    Class Bar;
    
    Class Bar
    {
      ...
      std::cin >> number;
      //call someFunction(number) from here
    }
    How can I accomplish this?
  • hype261
    New Member
    • Apr 2010
    • 207

    #2
    Originally posted by randysimes
    In a simple form, I fully understand how to do this.
    Code:
    //foo.h
    class Foo;
    
    Class Foo
    {
      void someFunction(int);
    }
    
    //foo.cpp
    #include <foo.h>
    
    int main()
    {
      Foo foo;
      foo.someFunction(bar);
      ...
      return 0;
    On the other hand, when I have:
    Code:
    //foo.h
    ...
    namespace myStuff
    {
      template typename < X, Y, Z >
      class Foo
      {
        void someFunction(int);
      }
    }; //namespace 
    
    //foo.cpp
    #include <foo.h>
    ...
    
    template typename <X, Y, Z>
    void Foo::someFunction(int)
    {
       //whatever
    }
    
    //bar.cpp
    #include <foo.cpp>
    ...
    Class Bar;
    
    Class Bar
    {
      ...
      std::cin >> number;
      //call someFunction(number) from here
    }
    How can I accomplish this?
    Because you have namespaced Foo to call the function you will need to scope the namespace also

    myStuff::foo::s omefunction();

    Also classes require ; at the end, but namespaces do not

    namespace myStuff
    {
    class Foo
    {
    };
    }

    Comment

    Working...