The following code compiles even though nonexisting_func()
doesn't exist. The code compiles because it's a member function of a templated class, but the function itself is not compiled because it's not being used in the program, correct? So you could have any syntax errors inside heapify_down
and the entire code should still compile?
#include <iostream>
#include <vector>
template<typename T>
class heap
{
public:
void heapify_down(std::vector<T> &vec)
{
nonexisting_func(vec);
}
};
int main( )
{
heap<int> my_heap;
return 0;
}
If my understanding above is correct, then why does the following code not compile?
#include <iostream>
#include <vector>
template<typename T>
class heap
{
public:
void heapify_down(std::vector<T> &vec)
{
a;
nonexisting_func(vec);
}
};
int main( )
{
heap<int> my_heap;
return 0;
}
Compiling this code gives me the error error: use of undeclared identifier 'a'
. Why is it trying to compile the heapify_down()
function now?