tags:

views:

86

answers:

2

Can it be done? I am looking for something different than using the member initialization list (because that is present in the definition, not necessarily the declaration).

Something like

class(args) : superclass(fn of args);
A: 

What forbid you from using member functions?

Klaim
The fact that virtual functions almost certainly don't work the way you think they do with a partially constructed object?
George
+2  A: 

What you are asking makes no sense.

In C++ each class has a constructor.
For a constructor the declaration defines the parameters.
For a constructor the definition defines how the parameters are used (like how they are passed to the base class).

Example:

Plop.h
=============
class Point
{
    public:
       Point(int x,int y);
};

class MyPoint: public Point
{
    public:
        MyPoint(int x);
        MyPoint(int x,int y);
        MyPoint(double z);
};

Plop.cpp
========
Point::Point(int x,int y)
{}

MyPoint::MyPoint(int x):       Point(x,x)           {}
MyPoint::MyPoint(int x,int y): Point(x*2,y-x)       {}
MyPoint::MyPoint(double z):    Point(sin(z),cos(z)) {}
Martin York
So if I have both a header file (.h) and a definition file (.cpp), I cannot use what you just did?
@drenami: Yes you can. But maybe if you explain what your problem is slightly better, then we can find a better way to explain it.
Martin York
Not how I wanted to do it, but like you alluded to, it's pointless to debate my conception of declaration versus reality.