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 7589149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:05:30+00:00 2026-05-30T20:05:30+00:00

I am trying to practice a little bit with cpp and want to make

  • 0

I am trying to practice a little bit with cpp and want to make a class of linked list and than to manipulate it reverse it, finding circle and etc. but I can’t understand what is the problem with my ctor/

I have this main:

#include "list.h"
#include <iostream>


using namespace std;


int main () {
  int x = 10;

  ListNode<int> node4();
  ListNode<int> node3(10 ,node4);
}

while this is “list.h” :

#ifndef LIST_NODE_H
#define LIST_NODE_H

#include <iostream>
using namespace std;

template <class T>
class ListNode {

  ListNode* next;
  T data;

 public:

  ListNode<T>( T dat = 0 ,const ListNode<T> &nex = NULL):data(dat),next(nex){};

};

#endif

I can’t understand why this line: ListNode<int> node3(10 ,node4);
makes this errors, what is the problem?

list.cpp: In function ‘int main()’: list.cpp:12:33: error: invalid
conversion from ‘ListNode ()()’ to ‘int’ [-fpermissive]
list.h:15:3: error: initializing argument 1 of
‘ListNode::ListNode(T, const ListNode&) [with T = int]’
[-fpermissive] list.cpp:12:33: warning: passing NULL to non-pointer
argument 1 of ‘ListNode::ListNode(T, const ListNode&) [with T =
int]’ [-Wconversion-null] list.cpp:12:33: error: recursive evaluation
of default argument for ‘ListNode::ListNode(T, const ListNode&)
[with T = int]’ list.h:15:3: warning: in passing argument 2 of
‘ListNode::ListNode(T, const ListNode&) [with T = int]’ [enabled
by default] list.h: In constructor ‘ListNode::ListNode(T, const
ListNode&) [with T = int]’: list.cpp:12:33: instantiated from
here list.h:15:76: error: cannot convert ‘const ListNode’ to
‘ListNode
’ in initialization

  • 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-05-30T20:05:31+00:00Added an answer on May 30, 2026 at 8:05 pm

    You have a number of errors with your code:

    1. In your constructor you have a null reference as your default value, which is invalid (see here).

    2. For a constructor with no arguments you need to omit the () (you can read about why here)

    Something like this should work:

    using namespace std;
    
    template <class T>
    class ListNode {
        ListNode* next;
        T data;
    
        public:
              ListNode<T>( T dat = 0 ,ListNode<T> * nex = NULL):data(dat),next(nex){};
    };
    
    
    int main(){
        ListNode<int> node4;
        ListNode<int> node3(10, &node4);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I'm trying to get some practice with Linked Lists. I Defined an Object
I'm trying to write a little Android application to store recipes as practice. To
Recently I was trying some practice programs in python and I came across this
I'm trying to practice writing better code, so I wanted to validate my input
I'm trying to practice my F# by writing small console scripts in F# in
I am fairly new to vim. I am trying to practice (been reading a
I'm using Eclipse with C++ plugins on my macbook, trying some practice projects to
Im trying to find a best practice to load usercontrols using Ajax. My first
I'm trying to complete a practice question from a book on generics but the
I am trying to establish the best practice for handling the creation of child

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.