Home > Back-end >  C compiler problem
C compiler problem

Time:11-25

Program is probably like this:
Template
The class Avl {
STD: : list{int the add item (const T *)
Pdata. Push_back (item);
}
};

The main () {
Node_t a;
AvlAvl. The add (& amp; A)
}

Then compile error is as follows:
In the file included the from../Welcome_1/welcome. Cc: 33:0:
./Welcome_1/Avl. H: In instantiation of 'int Avl : : add (const T *) T=node_t [with] : '
./Welcome_1/welcome. Cc: 129:15: the required from here
./Welcome_1/Avl. H: 112-5: error: no matching function for the call to 'push_back (const node_t * & amp;) '
Pdata. Push_back (item);
^
In the file included the from/usr/include/c + +/5.3.1/list: 63:0,
The from../Welcome_1/Avl. H: 11,
The from../Welcome_1/welcome. Cc: 33:
The/usr/include/c + +/5.3.1/bits/stl_list. H: 1088-7: note: candidate: void STD: : list
Push_back (const value_type & amp; __x)
^
The/usr/include/c + +/5.3.1/bits/stl_list. H: 1088-7: note: conversion of argument 1 whenever ill - formed:
In the file included the from../Welcome_1/welcome. Cc: 33:0:
./Welcome_1/Avl. H: 112-5: error: invalid conversion from 'const node_t *' to 'STD: : list 'Pdata. Push_back (item);

Don't understand why function parameters do not match, obviously the push_back (const value_type & amp; __x) should be the push_back (const node_t * & amp;) , please help to look at,

CodePudding user response:

This is a generic problem
List T here is including pointer
So to
STD: : list Pdata; It is ok that//generic T
{int the add item (T)
Pdata. Push_back (item);
return 0;
}

When call
Node_t a;
AvlAvl. The add (& amp; A);

Now compare the difference between yourself





CodePudding user response:

Building Lord:
Push_back (const value_type & amp; __x) and the push_back (const node_t * & amp;) Is not the same as
Value_type is compiled into node_t *, but the function parameter is (const value_type & amp; __x), at this time of const modifiers & amp; , equivalent to (value_type const & amp; __x)
So,
Push_back (const value_type & amp; __x) is equivalent to the push_back (node_t * const & amp;)

Push_back another overloading, rvalue references

Void push_back (_Ty & amp; & _Val)

& & , are rvalue references (a & amp; Is an lvalue reference),

CodePudding user response:

//ConsoleApplication1. CPP: this file contains the "main" function, the program will begin and end here, 
//

#include
#include

The class node_t {};
Template
The class Avl {
Public:
STD: : list{int the add item (const T *)
Pdata. Push_back (item);
return 0;
}
};


Int main ()
{
Node_t a;
AvlAvl. The add (& amp; A);
}

  • Related