Advertisement

02.28.2008 at 05:54AM PST, ID: 23200197
[x]
Attachment Details

Serializable class hierarchy - Probably deeper than just the syntax error

Asked by josgood in C++ Programming Language

I'd like to build a serializable class hierarchy containing a map of class names to constructors.

In the attached sample, I'm getting error C2059: syntax error : ')' on line 34.

Two questions:
1)  How can I fix my syntax error?  
2)  Can I somehow avoid the WithArg/WithOutArg macros?

Thank you.

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
#include <map>
#include <string>
#include <fstream>
#include <limits>
 
#define WithOutArg Shape* (* )(std::ifstream&)
#define WithArg(a) Shape* (*a)(std::ifstream&)
 
class Shape {
public:
   static void AddSerializableType(const std::string&, WithArg(a));
protected:
   Shape(std::ifstream&);
private:
   static std::map<std::string, WithOutArg> map;
};
 
std::map<std::string, WithOutArg> Shape::map;
void Shape::AddSerializableType(const std::string& name, WithArg(constructor)) {
   map.insert(make_pair(name,constructor));
}
 
class Circle : public Shape {
public:
   Circle(std::ifstream& str) : Shape(str) { 
      str.width(std::numeric_limits<double>::digits10);
      str >> m_radius;
   }
private:
   double m_radius;
};
 
int main() {
   Shape::AddSerializableType("Circle",Circle(std::ifstream&));
}
 
Keywords: Serializable class hierarchy - Probabl…
 
Loading Advertisement...
 
[+][-]02.28.2008 at 05:58AM PST, ID: 21003667

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.28.2008 at 06:05AM PST, ID: 21003743

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.28.2008 at 06:14AM PST, ID: 21003831

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.28.2008 at 06:14AM PST, ID: 21003836

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.28.2008 at 06:21AM PST, ID: 21003913

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]02.28.2008 at 09:58AM PST, ID: 21006333

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.28.2008 at 11:34AM PST, ID: 21007233

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C++ Programming Language
Sign Up Now!
Solution Provided By: evilrix
Participating Experts: 2
Solution Grade: A
 
 
[+][-]02.28.2008 at 12:59PM PST, ID: 21007998

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906