-1

I have a problem for calling the method of library "gum" in my program:

gum::BayesNet<double> *myBayNet=new gum::BayesNet<double>;
gum::DiscrereVariable* DV=new gum::DiscretizedVariable<double>;
int main()
{
  // error: invalid declaration
  // of 'gum::BayesNet<duoble>::add' & //forbids declaration of 'DV' 
  unsigned int gum::BayesNet<duoble>::add(const (*DV) str) 
  {
    return (*myBayNet).add(str);
  }
}

(See error message in comment.)

sbi
  • 219,715
  • 46
  • 258
  • 445
  • 1
    ...and the problem is...what? – Brian Kelly Apr 08 '12 at 18:46
  • I REALLY hope that the error is not the double misspelled... it's DOUBLE, not DUOBLE – Castilho Apr 08 '12 at 18:48
  • @BrianKelly: The error message is in a commend in the code. – sbi Apr 08 '12 at 18:49
  • the arguments (inputs) of add (const (*DV) str) is a class in DiscrereVariable. how can I define these inputs? – Shahram Khazaie Apr 08 '12 at 18:52
  • 2
    You urgently need a (better) [C++ book](http://stackoverflow.com/questions/388242/), Shahram. That code is awful — and I'm not referring to the syntax error of defining a member function in `main()`. Why are you using globals? Why are you allocating them dynamically? – sbi Apr 08 '12 at 18:54
  • gum::DiscreteVariable* DV=new gum::DiscreteVariable; template gum::BayNet *myBayNet=new gum::BayNet; unsigned int template gum::BayNet::add(const (*DV)) {int str;return (*myBayNet).add(str);} – Shahram Khazaie Apr 08 '12 at 19:06
  • gum::DiscreteVariable* DV=new gum::DiscreteVariable;template gum::BayNet *myBayNet=new gum::BayNet; unsigned int template gum::BayNet::add(const (*DV)) {int str;return (*myBayNet).add(str);} – Shahram Khazaie Apr 08 '12 at 19:14
  • can not allocate an object of abstract type gum::DiscreteVariable because des following virtual function are pure within DiscreteVariable...gum::DiscreteVariable::DoamneSize() – Shahram Khazaie Apr 08 '12 at 19:16

2 Answers2

2

DAFUQ is that const (*DV) str? DV is a variable and you are trying to use it as a typename. Also instead of writing (*myBayNet).add(str) simpler (and shorter) way is to write myBayNet->add(str).

Hauleth
  • 22,873
  • 4
  • 61
  • 112
1

You are not calling a method, your are defining it. However, you must not define member functions within main() or any other function scope. They must be defined at namespace scope.

sbi
  • 219,715
  • 46
  • 258
  • 445