This doesn't make sense to me

This is a discussion on This doesn't make sense to me within the C++ Programming forums, part of the General Programming Boards category; I am attempting to implement a function that will create a duplicate of a linked list and return a pointer ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    72

    This doesn't make sense to me

    I am attempting to implement a function that will create a duplicate of a linked list and return a pointer to the list. For this copy function to truly be a copy function, the elements in the new linked list need to be in the exact same order as the original

    When I compile the code below I get the following error:

    error C2780: '_OI __cdecl std::copy(_II,_II,_OI)' : expects 3 arguments - 1 provided

    Code:
    #include <iostream>
    
    #include "d_node.h"
    #include "d_nodel.h"
    
    using namespace std;
    
    template<typename T>
    node<T> *copy(node<T> *front);
    
    int main()
    {
        dnode<double> *header=new dnode<double>;
        dnode<double> *newList2=new dnode<double>;
    
    	insert(header->next, 5.5);
    	insert(header->next, 6.7);
    	insert(header->next, 15.3);
    	insert(header->next, 3.14);
    	insert(header->next, 2.718);
    	insert(header->next, 15.3);
    	insert(header->next, 3.5);
    
    	writeDLinkedList(header);
    
        newList2=copy(header);
    
    	writeDLinkedList(newList2);
    
    
    	return 0;
    }
    
    template<typename T>
    node<T> *copy(node<T> *front)
    {
    	dnode<T> *newList=new dnode<T>;
    	node<T> *curr=front;
    
    
    	while (curr !=NULL)
    	{
    		*newList.front()=front;
    		curr=curr->next;
    	}
    
    	return *newList;
    }
    From all that I can determine, my function only asks for/accepts one argument, but the compiler says it requires 3.. any ideas would be great!

    Thanks!

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    You have heard people saying you shouldn't use "using namespace std"? Well there already is a templated copy in the std namespace, and a max and a min and a count and all the good names for things. Remove using namespace std or rename your function deep_copy or something. The prototype also looks somewhat wrong to me, but I cannot put my finger on what the problem is.

    edit: should -> shouldn't

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    72
    Thank you for that advice, grib.. I eventually had to rename the function to d_copy so that the compiler would quit confusing it with the regular copy function ...

    I tested the code from where it initializes the linked list up until the part where it displays the list with the writeDLinkedList function, but everything else could be offbase, that's for sure... I'm still trying to tweak it ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Does this even remotely make sense
    By hckr83 in forum C Programming
    Replies: 6
    Last Post: 12-23-2005, 05:02 PM
  2. want to make this small program...
    By psycho88 in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2005, 02:05 AM
  3. Question about atheists
    By gcn_zelda in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 08-11-2003, 12:50 PM
  4. 'functions' in make?
    By mart_man00 in forum C Programming
    Replies: 1
    Last Post: 06-21-2003, 03:16 PM
  5. Foreigners don't make sense
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 04-25-2002, 03:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21