Question
I keep getting this error with this C++ code in a template: template sequence::size_type sequence::size() const //ERROR IS HERE { //at any point of time,
I keep getting this error with this C++ code in a template: template sequence::size_type sequence::size() const //ERROR IS HERE { //at any point of time, some are on first and some are on 2nd, //so the total of these stack size will be the number of elements //in sequence return first.size()+second.size(); } The error is : C:\Windows\system32\cmd.exe /C C:/TDM-GCC-64/bin/mingw32-make.exe -j4 SHELL=cmd.exe -e -f Makefile "----------Building project:[ 08-lab - Debug ]----------" need 'typename' before 'stack_sequence_4::sequence::size_type' because 'stack_sequence_4::sequence' is a dependent scope sequence::size_type sequence::size() const ^" What am I doing wrong? I think the code is good beside this part. Here is the code:
sequence4.h
// FILE: sequence4.h // CLASS PROVIDED: sequence // TYPEDEFS and MEMBER CONSTANTS for the sequence class: // typedef ____ size_type // sequence::size_type is the data type of any variable that keeps track of // how many items are in a sequence. //
// CONSTRUCTOR for the sequence class: // sequence( ) // Postcondition: The sequence has been initialized as an empty sequence. // // MODIFICATION MEMBER FUNCTIONS for the sequence class: // void start( ) // Postcondition: The first item on the sequence becomes the current item // (but if the sequence is empty, then there is no current item). // // void advance( ) // Precondition: is_item returns true. // Postcondition: If the current item was already the last item in the // sequence, then there is no longer any current item. Otherwise, the new // current item is the item immediately after the original current item. // // void insert(const value_type& entry) // Postcondition: A new copy of entry has been inserted in the sequence // before the current item. If there was no current item, then the new entry // has been inserted at the front of the sequence. In either case, the newly // inserted item is now the current item of the sequence. // // void attach(const value_type& entry) // Postcondition: A new copy of entry has been inserted in the sequence after // the current item. If there was no current item, then the new entry has // been attached to the end of the sequence. In either case, the newly // inserted item is now the current item of the sequence. // // void remove_current( ) // Precondition: is_item returns true. // Postcondition: The current item has been removed from the sequence, and the // item after this (if there is one) is now the new current item. // // CONSTANT MEMBER FUNCTIONS for the sequence class: // size_type size( ) const // Postcondition: The return value is the number of items in the sequence. // // bool is_item( ) const // Postcondition: A true return value indicates that there is a valid // "current" item that may be retrieved by activating the current // member function (listed below). A false return value indicates that // there is no valid current item. // // value_type current( ) const // Precondition: is_item( ) returns true. // Postcondition: The item returned is the current item in the sequence. // // VALUE SEMANTICS for the sequence class: // Assignments and the copy constructor may be used with sequence objects.
#ifndef _STACK_SEQUENCE_H_ #define _STACK_SAVITCH_SEQUENCE_H_ #include
template
template
second.push(first.top()); first.pop(); } if(!second.empty()) //if there is atleast one element, get that, its the 1st of sequence { first.push(second.top()); second.pop(); } }
template
template
template
if(!second.empty()) //now we need to get next element from the second stack, check if its empty { first.push(second.top()); second.pop(); } else //second is empty , so no more next element, dump all element from first onto second . So //we now dont have any current element since we are clearing out first { while(first.size()>0) {
second.push(first.top()); first.pop(); } }
} template
template
template
second.push(first.top()); first.pop(); } } }
}
#endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started