Question: i need help Compilation failed with errors: main.cpp: In function 'bool testDLinkedListConstructor ( ) ' : main.cpp: 3 8 : 2 7 : error: 'int

i need help
Compilation failed with errors:
main.cpp: In function 'bool testDLinkedListConstructor()':
main.cpp:38:27: error: 'int DLinkedList::size' is private within this context
38| assertCustom(list.size()==0, "Expected size =0, but got "+ std::to_string(list.size()));Recommendation: Check for recursive inclusion, unhandled exceptions, logical errors, or syntax issues in the code.
here is my code:
#include "DLinkedList.h"
#include
// Initialize the static variable activeNodes with 0 before main function
int DNode::activeNodes =0;
int main(){
DLinkedList list; // instance of DLinkedList
// Add 3 elements to the front of the list
list.addFront(10);
list.addFront(20);
list.addFront(30);
// Add 2 elements to the back of the list
list.addBack(40);
list.addBack(50);
// Traverse the list from head and print elements
std::cout << "List from head: ";
list.print(true);
// Traverse the list from trailer and print elements in reverse order
std::cout << "List from trailer: ";
list.print(false);
// Remove one element from the front and one from the back
list.removeFront();
list.removeBack();
// Print the list again after removals
std::cout << "List after front and back removals: ";
list.print(true);
// Add another element to the front and one to the back
list.addFront(60);
list.addBack(70);
// Print the list after all operations
std::cout << "Final list: ";
list.print(true);
// Display the current size of the list
std::cout << "Current List Size: "<< list.getSize()<< std::endl;
// Display the number of active nodes
std::cout << "Active Nodes: "<< list.activeNodeCount()<< std::endl;
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!