c++ new operator error

Asked 1 years ago, Updated 1 years ago, 125 views

https://github.com/j209446/BST_bag_class-c-/blob/master/main.cpp This is my cpp file. When I built it on VS2015, I got a C2668 error An error occurs in the new operator, but I don't know why.

node->set_left(new binary_tree_node<item> ) If I do this, it comes out as ambiguous, and even if I do it like this, it's ambiguous. How do I solve it?

c++ visual-studio-2015 new operator-overloading

2022-09-22 19:05

1 Answers

This is because there is a problem with the constructor declaration of binary_tree_node.

If you look at the constructor part in the code you showed me, it is as follows.

binary_tree_node();
binary_tree_node<T>(const binary_tree_node& copy);
binary_tree_node<T>(const T& init_data = T(), binary_tree_node* init_left = NULL, binary_tree_node* init_right = NULL);

If you look at the third constructor, the default values are applied to all call factors.

binary_tree_node<int>()

This could be the first constructor, or the third constructor with all the default values applied.

To resolve the problem, remove the default values for the init_data variable as shown below.

binary_tree_node<T>(const T& init_data, binary_tree_node* init_left = NULL, binary_tree_node* init_right = NULL);


2022-09-22 19:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.