copy constructor issues HELP

Hello. I'm currently wrapping up on a project which uses a doubly linked list toolkit to work with a sequence class. During which I can't get my copy constructor to function with my given driver (can't change driver)

I get this code
error C2274: 'function-style cast' : illegal as right side of '.' operator

Below i will include both my driver and my sequence implementation. However also in this program is my dnode.h and dnode.cpp(implement) files with the following functions to aid
1
2
3
4
5
6
7
8
9
10
11
12
size_t list_length(const dnode* head_ptr);
	void display(const dnode* head_ptr);
    void list_head_insert(dnode*& head_ptr, const value_type& entry); 
    void list_insert(dnode* previous_ptr, const value_type& entry);  
    dnode* list_search(dnode* head_ptr, const value_type& target);
    const dnode* list_search (const dnode* head_ptr, const value_type& target);
    dnode* list_locate(dnode* head_ptr, size_t position);
    const dnode* list_locate(const dnode* head_ptr, size_t position);
    void list_head_remove(dnode*& head_ptr);
    void list_remove(dnode* remove_ptr);
    void list_clear(dnode*& head_ptr);
    void list_copy(const dnode* source_ptr, dnode*& head_ptr, dnode*& tail_ptr);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <cassert>    // Provides assert
#include <cstdlib>    // Provides NULL and size_t
#include <iostream>
#include"sequence2.h"

//Constructor
sequence::sequence( )
{
	head_ptr = NULL;
	current_ptr = NULL;
}

//Copy Constructor
sequence::sequence(const sequence & source)
{		
        dnode * tail_ptr;
	list_copy(source.head_ptr, head_ptr, tail_ptr);
	if(source.current_ptr != NULL)
	   current_ptr = list_search(head_ptr, source.current_ptr->data());
	else
		current_ptr = NULL;
        
       
	

}

//Destructor
sequence::~sequence()
{
	list_clear(head_ptr);
	current_ptr = NULL;
}

//Has the current pointer equal the start
void sequence::start()
{
	current_ptr = head_ptr;
	
}

//Displays the list
void sequence::show_sequence()
{
	display(head_ptr);
}

}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include<iostream>
#include <cctype>       // Provides toupper
#include <cstdlib>      // Provides EXIT_SUCCESS
#include"sequence2.h"

using namespace std;

// PROTOTYPES for functions used by this test program:
void print_menu( );
// Postcondition: A menu of choices for this program has been written to cout.

char get_user_command( );
// Postcondition: The user has been prompted to enter a one character command.
// The next character has been read (skipping blanks and newline characters), 
// and this character has been returned.

double get_number( );
// Postcondition: The user has been prompted to enter a real number. The
// number has been read, echoed to the screen, and returned by the function.

sequence cctest(const sequence & source);

int main( )
{
    sequence test, test2; // A sequence that we'll perform tests on
    char choice;   // A command character entered by the user
    dnode * head = NULL;

    cout << "I have initialized an empty sequence of real numbers." << endl;

    do
    {
        print_menu( );
        choice = toupper(get_user_command( ));
        switch (choice)
        {
            case '!': test.start( );
                      break;
		    case '+': test.advance( );
                      break;
			case '-': test.moveback();
				      break;
			case '=': test2 = test;
				      test2.show_sequence();
				      break;
            case '?': if (test.is_item( ))
                          cout << "There is an item." << endl;
                     else 
                          cout << "There is no current item." << endl;
                      break;
            case 'C': if (test.is_item( ))
                           cout << "Current item is: " << test.current( ) << endl;
                     else
                          cout << "There is no current item." << endl;
                      break;
			case 'X': test.sequence( ); // ERROR ON THIS LINE
				cout << "Testing the copy function" << endl;
				     break;
            case 'P': test.show_sequence();
                      break;
            case 'S': cout << "Size is " << test.size( ) << '.' << endl;
                      break;
            case 'I': test.insert(get_number());
                      break;
            case 'A': test.attach(get_number());
                      break;
			case 'T': test.tail();
				      break;
			case 'R': test.remove_current( );
                      cout << "The current item has been removed." << endl;
                      break;
			case 'D': test.~sequence();
				      break;     
            case 'Q': cout << "Ridicule is the best test of truth." << endl;
                      break;
			
            default:  cout << choice << " is invalid." << endl;
        }
    }
    while ((choice != 'Q'));

    return EXIT_SUCCESS;
}

void print_menu( )
{
    cout << endl; // Print blank line before the menu
    cout << "The following choices are available: " << endl;
    cout << " !   Activate the start( ) function" << endl;
    cout << " +   Activate the advance( ) function" << endl;
	cout << " -   Activate the moveBack() function" << endl;
	cout << " =   Activate the operator= function" << endl;
    cout << " ?   Print the result from the is_item( ) function" << endl;
    cout << " C   Print the result from the current( ) function" << endl;
	cout << " X   Activate the Copy Constructor" << endl;
    cout << " P   Print the entire sequence" << endl;
    cout << " S   Print the result from the size( ) function" << endl;
    cout << " I   Insert a new number with the insert(...) function" << endl;
    cout << " A   Attach a new number with the attach(...) function" << endl;
	cout << " T   Activate the tail() function" << endl;
    cout << " R   Activate the remove_current( ) function" << endl;
	cout << " D   To destory the list(destructor)" << endl;
    cout << " Q   Quit this test program" << endl;
}

char get_user_command( )
{
    char command;

    cout << "Enter choice: ";
    cin >> command; // Input of characters skips blanks and newline character

    return command;
}


double get_number( )
{
    double result;
    
    cout << "Please enter a real number for the sequence: ";
    cin  >> result;
    cout << result << " has been read." << endl;
    return result;
}

sequence cctest(const sequence & source)
{
	sequence test(source);

	return test;
}
> test.sequence( ); // ERROR ON THIS LINE
¿what do you think you are doing there?

> case 'D': test.~sequence();
bad idea
the destructor is invoked automagically when the variable goes out of scope, so you'll end calling it twice
Topic archived. No new replies allowed.