Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7844065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:45:50+00:00 2026-06-02T16:45:50+00:00

I am a beginner in c++ so please excuse me if I my mistakes

  • 0

I am a beginner in c++ so please excuse me if I my mistakes below turn out to be silly. Still, I am stuck with my code and would appreciate any help.

I get the following error when trying to compile through make via g++:

In file included from A.cpp:2:
List.h:20: error: ‘List’ is not a template type
A.cpp: In member function ‘void A::NowyObiekt(int)’:
A.cpp:6: error: ‘list_a’ was not declared in this scope
make: *** [A.o] Error 1

My code is separated into the following tiny files:

  • A.h : http://pastebin.com/QQ04xx2j (header)
  • A.cpp : below

    #include "A.h"
    #include "List.h"
    
    void A::NewObject(int i)
    {
            list_a.Add(i);
    }
    
    int A::Compare(int a, int b)
    {
            if ( a>b ) return 1;
            if ( a<b ) return -1;
            else return 0;
    }
    
  • List.h : below (header)

    #ifndef LIST_H
    #define LIST_H
    template<typename T>
    class Node
    {
        Node()
        {
            nxt = pre = 0;
        }
        Node(const T& el, Node *n = 0, Node *p = 0 )
        {
            dana = el; nxt = n; pre = p;
        }
        T dana;
        Node *nxt, *pre;
    };
    
    template<typename T>
    class List
    {
    public:
        List()
        {
            head = tail = 0;
        }
        void Add(const T&);
    protected:
        Node<T> *head,*tail;
    };
    
    #endif
    
  • List.cpp : http://pastebin.com/a3HQ9yZ4

  • prog.cpp : below (main)

    #include "List.h"
    #include "A.h"
    
    int main()
    {
        int i = 5;
        class List list_a;
        class A obj;
    
        obj.Add(i);
    }
    
  • and the makefile is : http://pastebin.com/GTR5jW54

As noted, I am still a beginner, so please be understanding. I would be thankful for any help and clear explanations. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T16:45:51+00:00Added an answer on June 2, 2026 at 4:45 pm

    There are a couple of problems with your code: The first is that you don’t declare any variable named list_a anywhere. That error should be pretty obvious. The other is that you use the List class without giving it template parameters.

    And last a small note about your question: As your files are indeed very small, you could put them in the question and not link to them.

    Edit: About the List template problem.

    You already use Node properly in List, i.e. declare the nodes as Node<T>. When you use List you simply has to do the same. For example, to declare a list of integers:

    List<int> my_int_list;
    

    Also, as you only use public functions in List from the class A, you don’t need the friend declaration. If you do need to use protected or private members (which IMO is a sign of bad design) you need to make that friend-declaration templated as well:

    friend class List<sometype>;
    

    And finally, your code will not compile anyway… The reason being that when you are using a template-class, the whole class has to be fully defined (i.e. complete with its function implementations). You can solve this by putting the functions in the header file. And when defining the functions, you need the template parameter there as well:

    template<typename T>
    void List<T>::Add(const T& el)
    {
        Node<T>* head = new Node<T>(el);
        if ( Compare(el,i) > i )
            std::cout << "Ok" << std::endl;
    }
    

    Note that I added the template parameter in a couple of places.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

please can you help a jquery beginner out? I don't really know how to
I'm a perl beginner, please help me out with my query... I'm trying to
Please help this beginner here... I have a SQL Server 2008 R2 running on
Im a beginner to css, please can someone help me get this element to
Could someone please help me in here, I'm just a beginner who want to
please, can you help me with this? I am a beginner in programming, so
I am beginner with java, please forgive me if I do make any error
I am beginner in AWK , so please help me to learn it. I
I am a beginner to PHP so please forgive any ignorance... I am using
Please pardon the beginner question.I met this code fragment on the internet: public class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.