Click here to Skip to main content
15,904,986 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
C++
class A {
   public:
      virtual ~A() {};
      virtual int emit(int t, void* a)=0;
};

template <class dest_type="">
class B : public A {
   public:
      typedef int (dest_type::*classpfn)(int, void*);
      B(dest_type* pclass, classpfn pfn) : p(pclass), fn(pfn) {};
      virtual int emit(int t, void* a) { return (p->*fn)(t, a); }
   private:
      dest_type *p;
      classpfn fn;
};

Output:
=======
abc.h:222: error: expected unqualified-id before ‘int’
abc.h:222: error: expected ‘)’ before ‘int’
Posted
Updated 27-Mar-12 5:37am
v5
Comments
Pablo Aliskevicius 26-Mar-12 11:12am    
Which line is 222?
Are you using GCC?
What do you mean by <class dest_type="">? Shouldn't the default be a class name?
enhzflep 26-Mar-12 11:35am    
Using gcc the messages are different and somewhat more helpful:

main.cpp|7|error: expected type-specifier before string constant
main.cpp|7|error: expected '>' before string constant
(line 7 is same as line 7 in above code snippet)

To fix, just remove the ="" from the 2nd class definition
Stefan_Lang 27-Mar-12 11:19am    
I modified the question to again show the source code originally posted. Whoever modified that code to something different just served to confuse everyone else...

P.S.: I also voted to make up for that unjustified 1-vote. No idea why this was voted down, it is a totally legitimate question.
Stefan_Lang 27-Mar-12 11:39am    
P.P.S.: modified it back to show
template <class dest_type="">

I was misled by the fact that viewing the original version did no show the last part - only viewing the differences from the first to the second revision let me see that the template argument list was actually there from the start ...
Stefan_Lang 27-Mar-12 11:51am    
Sorry for the confusion, but it seems that your various responses were not printed correctly as the < and > symbols required to show the template argument was incorrectly rendered as a (unknown, and therefore ignored) HTML tag by this site.

The response in solution 1 is correct: you cannnot use an empty string to initialize a template argument of type class. I believe I have seen something like that elsewhere (maybe Java?), but in C++ this syntax is not possible. There is no 'empty' class.

1 solution

This part template<class dest_type="">, looks weird to me, are you trying to set the default type dest_type to an empty string?

Try removing that so that you're left with template<class dest_type>.

Hope this helps,
Fredrik
 
Share this answer
 
Comments
Charmy from bangalore 26-Mar-12 11:55am    
class A {
public:
virtual ~A() {};
virtual int emit(int t, void* a)=0;
};

template<class dest_type=""> //this is actual
class B : public A {
public:
typedef int (dest_type::*classpfn)(int, void*);
B(dest_type* pclass, classpfn pfn) : p(pclass), fn(pfn) {};
virtual int emit(int t, void* a) { return (p->*fn)(t, a); }
private:
dest_type *p;
classpfn fn;
};

Output:
=======
abc.h:222: error: expected unqualified-id before ‘int’
abc.h:222: error: expected ‘)’ before ‘int’
Iam getting error in these 2 lines
==================================
virtual int emit(int t, void* a)=0;
virtual int emit(int t, void* a) { return (p->*fn)(t, a); }
Charmy from bangalore 26-Mar-12 11:55am    
Iam using g++ compiler
nv3 26-Mar-12 14:08pm    
I replaced your line

template // this is actual

with

template< class dest_type="">

Then it compiles without error on VC++. Neither your original version (with dest_type="") nor the version in the comment of an hour ago do compile though. Please try that line and if you still get an error, specify precisely which line the compiler dislikes.
Charmy from bangalore 27-Mar-12 0:25am    
class A {
public:
virtual ~A() {};
virtual int emit(int t, void* a)=0;
};
template<class dest_type="">
class B : public A {
public:
typedef int (dest_type::*classpfn)(int, void*);
B(dest_type* pclass, classpfn pfn) : p(pclass), fn(pfn) {};
virtual int emit(int t, void* a) {
return (p->*fn)(t, a);
}

Output:
=======
abc.h:222: error: expected unqualified-id before ‘int’
abc.h:222: error: expected ‘)’ before ‘int’
Iam getting error in these 2 lines in the function arguments
============================================================
virtual int emit(int t, void* a)=0;
virtual int emit(int t, void* a) { return (p->*fn)(t, a); }
Charmy from bangalore 27-Mar-12 0:29am    
Iam getting error in these 2 lines in the function arguments ============================================================
virtual int emit(int t, void* a)=0;
virtual int emit(int t, void* a) { return (p->*fn)(t, a); }

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900