0
#AL.hpp
template <typename A>
class AL
{
    public:
        void print(A *source, A *dest, unsigned int size);
    private:
        A *data;
        unsigned int size;
        unsigned int capacity;
 }

namespace {
    template <typename A>
    unsigned int size s_size = 20;
    void print(A *source, A *dest, unsigned int size)
    {
      ....
    }
 }

template <typename A>
AL<X>& AL<X>::push(A input)
{
    capacity *= 2;
    A *new_data = new A[capacity];
    print(data, new_data, size);
 }

I am just wondering how to format this (please don't mind the code). When I run my full code, it says that A is not defined in the namespace. I'm not sure how to pass in the class template to my namespace.

5
  • 2
    Can you post code that is at least close to being valid? Commented Aug 8, 2014 at 5:15
  • Are you trying to provide the definition for the member function in a different namespace? Commented Aug 8, 2014 at 5:15
  • 1
    Are you trying to make the whole namespace templated? Or the function print? Because you can't make templated namespaces. If you want a templated "namespace" you have to make a struct with only static members. Commented Aug 8, 2014 at 5:17
  • i want to use the print function in another function that has template, but i get an error message saying that A is undefined in the namespace. i'm not sure how to get the values to pass through one another. Commented Aug 8, 2014 at 5:51
  • 1
    So you want the function to be templated? Then look again at the source, especially where you placed the template declaration for the function (or rather, it's not a template declaration for the function, but for the variable declaration, which itself is not valid). Commented Aug 8, 2014 at 5:53

1 Answer 1

1
#AL.hpp
template <typename A>
class AL
{
    public:
        AL(A array_list);
        AL(const AL& other);
        AL& operator=(const AL& other);
        ~AL;
        void print(A *source, A *dest, unsigned int size);
}

namespace {
    unsigned int size s_size = 20;
    template <typename A>
    void print(A *source, A *dest, unsigned int size)
    {
       ....
    }
 }

If the problem or error is your 'print' function is seemed unnamed then this is the solution.I hope this will help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.