
Hi ppl-gr, I used the function set_output_function() how you suggest me. When I use it in a single program like in your tests example it works correctly, but when I use it in a class I must declare it static; I used it in a my_print function in order to print the ph for each comand.
I think that this happens for this reason: since the namespace Variable have static member when I used the functions of this namespace in a class (an object which can be initialized more times) I must declare them static.
The problem is in this class:
class Cmd{
public:
//ph which I have in each statement NNC_Polyhedron ph_in;
//these are Hashmap the first element is the dimension //and the second the variable to print static map<dimension_type, string> var_to_print; static map<dimension_type, string>::iterator iter;
public:
static void Cmd::new_output_function(ostream& s, const Variable v) { iter = var_to_print.find(v.id()); s << iter->second; }
void Cmd::print_constraints(const ConSys& cs, const string& intro, ostream& s){ using namespace IO_Operators;
// Save the default output function. Variable::Output_Function_Type* p_default_output_function = Variable::get_output_function();
// Install an alternate output function. Variable::set_output_function(new_output_function);
/* Your code of print_constraints() */
/* Code to restore the default output function. */
[...] };
when I compile it the g++ gives me these errors:
/tmp/ccOzbfS7.o(.gnu.linkonce.t._ZN3Cmd19new_output_functionERSoN23Parma_Polyhedra_Library8VariableE+0x24): In function `Cmd::new_output_function(std::basic_ostream<char, std::char_traits<char> >&, Parma_Polyhedra_Library::Variable)': : undefined reference to `Cmd::var_to_print' [...] : undefined reference to `Cmd::iter' [...]
Sorry but I am a java-programmer and sometimes when I used c++ I make some stupid mistake.
All the bests,
Enrico.

Enrico Oliosi wrote:
I used the function set_output_function() how you suggest me. When I use it in a single program like in your tests example it works correctly, but when I use it in a class I must declare it static; I used it in a my_print function in order to print the ph for each comand.
I think that this happens for this reason: since the namespace Variable have static member when I used the functions of this namespace in a class (an object which can be initialized more times) I must declare them static.
Dear Enrico,
what you say above makes little sense to me, and the code you attached does not clarify the situation. In general, if you can send us a complete example (i.e., one that compiles) there are more chances we can be helpful. My suggestion is to forget about what you wrote above and declare `static' what you want to be static and non-static what you want to be non-static. Then we will see what the actual problem is.
The problem is in this class:
class Cmd{
public:
//ph which I have in each statement NNC_Polyhedron ph_in;
//these are Hashmap the first element is the dimension //and the second the variable to print static map<dimension_type, string> var_to_print; static map<dimension_type, string>::iterator iter;
Why is `iter' a member of the class?
public:
static void Cmd::new_output_function(ostream& s, const Variable v) { iter = var_to_print.find(v.id()); s << iter->second; }
Why isn't `iter' local to this function? (And, by the way, why don't you check whether `v' was actually found or not?)
void Cmd::print_constraints(const ConSys& cs, const string& intro, ostream& s){ using namespace IO_Operators;
// Save the default output function. Variable::Output_Function_Type* p_default_output_function = Variable::get_output_function(); // Install an alternate output function. Variable::set_output_function(new_output_function); /* Your code of print_constraints() */ /* Code to restore the default output function. */ [...]
};
Looks reasonable.
when I compile it the g++ gives me these errors:
/tmp/ccOzbfS7.o(.gnu.linkonce.t._ZN3Cmd19new_output_functionERSoN23Parma_Polyhedra_Library8VariableE+0x24): In function `Cmd::new_output_function(std::basic_ostream<char, std::char_traits<char> >&, Parma_Polyhedra_Library::Variable)': : undefined reference to `Cmd::var_to_print' [...] : undefined reference to `Cmd::iter' [...]
This seems to be a FAQ, indeed: see http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.10
I hope this helps. If not, please come back to us. All the best,
Roberto

Sorry, my explanation has not been exhaustive. I attach two files, one compiles and the other doesn't.
Hope that this is more clareful!
Thanks, Enrico.

Enrico Oliosi wrote:
my explanation has not been exhaustive. I attach two files, one compiles and the other doesn't.
Dear Enrico,
I did not even look to the file you called `compile.cc' as I thought your true intentions were more faithfully represented by `notcompile.cc'. The attached version (which can be very much improved) should put you on the right track. Notice that I have deliberately chosen to use the just released PPL 0.6, so that you will have to upgrade your installation (and this way you will have an opportunity to do us a favor by checking that everything is OK :-) All the best,
Roberto

[Resent after reconfiguring the mailing list software so as to allow attachments of type text/x-c++. RB]
Enrico Oliosi wrote:
my explanation has not been exhaustive. I attach two files, one compiles and the other doesn't.
Dear Enrico,
I did not even look to the file you called `compile.cc' as I thought your true intentions were more faithfully represented by `notcompile.cc'. The attached version (which can be very much improved) should put you on the right track. Notice that I have deliberately chosen to use the just released PPL 0.6, so that you will have to upgrade your installation (and this way you will have an opportunity to do us a favor by checking that everything is OK :-) All the best,
Roberto
participants (2)
-
Enrico Oliosi
-
Roberto Bagnara