templates - C++ argument should be passed by value, but compiler sees it as reference -


so weird behaviour not understand. have:

template <typename t> node node::apply() {     return ptr->graph->derived_node(std::make_shared<t>(ptr->graph, this)); } template <typename t> node apply(node parent1, node parent2){     graphinptr graph = parent1.ptr->graph;     return graph->derived_node(std::make_shared<t>(graph, parent1, parent2)); } template <typename t> node apply(nodevec parents){     graphinptr graph = parents[0].ptr->graph;     return graph->derived_node(std::make_shared<t>(graph, parents)); } 

i have this:

node gt(node node1, node node2){         return apply<greaterthan>(node1, node2); } 

however, here compiles error:

node node::gt(node node) {         return apply<greaterthan>(node(this), node); } 

the error is:

error: no matching function call ‘metadiff::node::apply(metadiff::node, metadiff::node&)’          return apply<greaterthan>(node(this), node); note: candidate is: note: template<class t> metadiff::node metadiff::node::apply()      node node::apply() 

so reason trying call node::apply() instead of apply(node node1, node node2), don't understand why? , why interpreted node node&?

interestingly enough worked:

node node::gt(node node) { //        return apply<greaterthan>(node(this), node);         graphinptr graph = ptr->graph;         return graph->derived_node(std::make_shared<greaterthan>(graph, this, node));     } 

nevertheless, i'm curious going on?!

and why interpreted node node&?

that's red herring. it's compiler's way of showing value category of second argument (which lvalue, &).


your actual problem in member function, class member node::apply hides namespace-scope function templates of same name. if want call latter, qualify call:

return mynamespace::apply<greaterthan>(node(this), node); 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -