0

It's a Heap implemented by myself(for algorithm contest).There are some compilation errors that I can't recover from...

\Map_Heap.cpp|13|error: invalid use of non-static data member 'MapHeap<DT>::nv'| \Map_Heap.cpp|19|error: from this location| 

Code:

#include<cstdio> #include<cstring> const int HEAP_SIZE=10005; template<class DT> struct MapHeap { DT f[HEAP_SIZE+5]; int mp1[HEAP_SIZE+5];//val -> index int mp2[HEAP_SIZE+5];//index -> val int nv;///line 13 MapHeap():nv(0) { memset(mp1,-1,sizeof(mp1)); memset(mp2,-1,sizeof(mp2)); } void print(int n=nv)//line 19 { for(int i=1;i<=n;i++) printf("%d ",f[i]); puts(""); for(int i=1;i<=n;i++) printf("%d ",mp1[i]); puts(""); for(int i=1;i<=n;i++) printf("%d ",mp2[i]); puts(""); } }; 
2
  • There are some funny **s at the front. Are these part of the code, or were you trying to make that line bold? Because that won't work in code. Commented Mar 25, 2012 at 19:51
  • 1
    I were just trying to make that line bold and I found it didn't work...>_< Commented Mar 25, 2012 at 19:53

1 Answer 1

8

It's simply saying that you can't base a default argument on a member variable. Consider using overloads instead:

void print() { print(nv); } void print(int n) { ... } 
Sign up to request clarification or add additional context in comments.

3 Comments

Is it mentioned explicitly in the Standards that "you can't base a default argument on a member variable?
wow..It's cool.. It's just steer clear of the problem...(I am not a English native speaker...sorry for my poor English if I make any misunderstanding)
@Mr.TAMER. Actually, yes. See 8.3.6, clause 9: "a non-static member shall not be used in a default argument expression".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.