constructors not allowed a return type - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

constructors not allowed a return type

tsagldtsagld Posts: 621Member
Now I have one for you:

I have this code:

in .h:
[code]
class CVariable
{
protected:
void Initialize(LPTSTR as_Name, DWORD adw_Type);
public:
CVariable(LPTSTR as_Name, DWORD adw_Type);
};
[/code]
in .cpp:
[code]
CVariable::CVariable(LPTSTR as_Name, DWORD adw_Type)
{
Initialize(as_Name, adw_Type);
}

void CVariable::Initialize(LPTSTR as_Name, DWORD adw_Type)
{
...
}
[/code]

Compilation under VC++ 6.0 gives me:
'error C2533: 'CVariable::CVariable' : constructors not allowed a return type'

Does any of you see a return type declared??? I don't!!! What's the problem here?

Thanx,
Eric.

Comments

  • PeterTheMasterPeterTheMaster Posts: 636Member
    please show what is directly above
    [code]
    CVariable::CVariable(LPTSTR as_Name, DWORD adw_Type)
    {
    Initialize(as_Name, adw_Type);
    }
    [/code]

    and a tip for better readability: put the public section in the class declaration above the private section. this also emphasizes that the public part is what the user of the class should read.
  • tsagldtsagld Posts: 621Member
    There is nothing above but the #include "variable.h"
    The code in the .h is shown in my first post.
    Weird, isn't it?

    : please show what is directly above
    : [code]
    : CVariable::CVariable(LPTSTR as_Name, DWORD adw_Type)
    : {
    : Initialize(as_Name, adw_Type);
    : }
    : [/code]
    :
    : and a tip for better readability: put the public section in the class declaration above the private section. this also emphasizes that the public part is what the user of the class should read.
    :

  • PeterTheMasterPeterTheMaster Posts: 636Member
    thats really weird.
    what about making this constructor inline(=putting the definition in the declaration)? this is reasonable anyway since it only wraps another function call.
  • tsagldtsagld Posts: 621Member
    It's getting weirder.
    I tried your suggestion and out-commented the code in the .cpp.
    The first code in the cpp after the outcommented code now is de destructor:
    [code]
    CVariable::~CVariable()
    {
    }
    [/code]
    which is empty, as you can see.
    Compilation gives me this:
    error C2631: 'CVariable::~CVariable' : destructors not allowed a return type

    Now I could go on and make the destructor inline too, but I would really like to know what is going on here.
    What I didn't mention before, is that I have several derived classes from CVariable whose constructors call the base-constructor. Those constructor-calls give me errors too:
    error C2264: 'CVariable::~CVariable' : error in function definition or declaration; function not called
    That makes sense offcourse, but I mention it now to be complete.

    Would you like to have my entire source to try and make it compile?
    It is not much more than I posted yet.

    : thats really weird.
    : what about making this constructor inline(=putting the definition in the declaration)? this is reasonable anyway since it only wraps another function call.
    :

  • tsagldtsagld Posts: 621Member
    Stupid me!
    I like to think of myself as an experienced programmer, but hey, sometimes I look with my toes.
    In the .h file I declared several classes, and there was no semicolon at the end of the last declaration.
    So you were close when you asked what was directly before the first line in the .cpp.

    Thanx anyway!

    Greets,
    Eric Goldstein
    www.gvh-maatwerk.nl

Sign In or Register to comment.