Solved

VC++ 6.0 constructors not allowed a return type?!??!

Posted on 2004-04-07
20
2,038 Views
Last Modified: 2007-12-19
Hey All,
Please help if you can, I'm sure it's something simple (isn't it always!! :) ) but it has me baffled.
I am writing some C++ classes, Multiplexor has a subclass called AllStreamsMuxer See the following code:

-----------------------------------MULTIPLEXOR.H---------------------------------------

#ifndef _Multiplexor_H_
#define _Multiplexor_H_

class Multiplexor
{
      public:
            struct UnmuxedPacket
            {
                  Float64 cts;
                  int payload_length;
                  char header_data[RTP_HEADER_SIZE];
                  char payload_data[MAX_MTU_SIZE];
            };

            Multiplexor();
            ~Multiplexor();
            virtual Float64 getPacket(char ** outPacket, int * outPacketLength);

      protected:
            char multiplexed_packet[MAX_MTU_SIZE];

            virtual UInt32 getFullBufferEsId();                  
};

#endif // _Multiplexor_H_

----------------------------------MULTIPLEXOR.CPP----------------------------------------

#include "Multiplexor.h"

Multiplexor::Multiplexor()
{
      
}

Multiplexor::~Multiplexor()
{
      
}

------------------------------ALLSTREAMSMUXER.H------------------------------------------

#ifndef _AllStreamsMuxer_H_
#define _AllStreamsMuxer_H_

#include "Multiplexor.h"

class AllStreamsMuxer : public Multiplexor
{
      public:
            AllStreamsMuxer();
            ~AllStreamsMuxer();

      private:
            UnmuxedPacket multiplex_buffer[MAX_PACKETS_PER_MUX_PACKET];
            UInt32 current_buffer_location;
};

#endif // _AllStreamsMuxer_H_

------------------------------------ALLSTREAMSMUXER.CPP-----------------------------------------------------

#include "AllStreamsMuxer.h"

AllStreamsMuxer::AllStreamsMuxer()
{
      current_buffer_location = 0;
}

AllStreamsMuxer::~AllStreamsMuxer()
{
      
}

Float64 Multiplexor::getPacket(char ** outPacket, int * outPacketLength)
{
      return 5.5;
}

UInt32 Multiplexor::getFullBufferEsId()
{
      return 1;
}

-----------------------------------------------------------------------------------------------------------------
The problem is that it won't compile and it gives the error:
"AllStreamsMuxer.cpp(4) : error C2533: 'AllStreamsMuxer::AllStreamsMuxer' : constructors not allowed a return type"

I can't see how it is picking up a returned typed ( I suspect that another error has confused the compiler and causing an incorrect diagnosis).  I have looked at http://lists.wxwidgets.org/archive/wx-users/msg21063.html but I can't see any relation, I appear to have the semicolon in the right place as far as I can see.
I would be grateful for your suggestions / solutions.
Stef
0
Comment
Question by:stefarg
  • 8
  • 6
  • 4
  • +2
20 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 10780128
Hum. Regarding the code you posted, there don't seem to be any obvious problems...
0
 
LVL 1

Author Comment

by:stefarg
ID: 10780208
Yeah, that's what I thought, but I just thought that someone who hasn't been bogged down in the code may be able to spot the problem (hopefully!)
0
 
LVL 86

Expert Comment

by:jkr
ID: 10780224
Any problems with the other header files? I mean, a few of the data types you are using are not declared in the above code...
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 3

Assisted Solution

by:idt
idt earned 100 total points
ID: 10780264
I added

#define RTP_HEADER_SIZE 1
#define MAX_MTU_SIZE 1
#define MAX_PACKETS_PER_MUX_PACKET 1
typedef double Float64;
typedef unsigned long UInt32;

to Multiplexor.h

and both cpp files compiled to object code just fine except:
note that class Multiplexor has virtual functions yet the destructor is non-virtual
and the same for class AllStreamsMuxer

So.. to compile totally clean

in Multiplexor.cpp
//Multiplexor::~Multiplexor()
//{
//
//}

in Allstreamsmuxer.cpp
//AllStreamsMuxer::~AllStreamsMuxer()
//{
//
//}

in Allstreamsmuxer.h
//~AllStreamsMuxer();
virtual ~AllStreamsMuxer();

in Multiplexor.h
//~Multiplexor();
virtual ~Multiplexor();

Daniel
0
 
LVL 86

Expert Comment

by:jkr
ID: 10780267
>>So.. to compile totally clean

Did that yield any errors?
0
 
LVL 86

Expert Comment

by:jkr
ID: 10780281
Ooops, forget about my last post...

I just compiled the following as a single .cpp file without any problems:

#define RTP_HEADER_SIZE 1
#define MAX_MTU_SIZE 1
#define MAX_PACKETS_PER_MUX_PACKET 1
typedef double Float64;
typedef unsigned long UInt32;

//-----------------------------------MULTIPLEXOR.H---------------------------------------

#ifndef _Multiplexor_H_
#define _Multiplexor_H_

class Multiplexor
{
    public:
         struct UnmuxedPacket
         {
              Float64 cts;
              int payload_length;
              char header_data[RTP_HEADER_SIZE];
              char payload_data[MAX_MTU_SIZE];
         };

         Multiplexor();
         ~Multiplexor();
         virtual Float64 getPacket(char ** outPacket, int * outPacketLength);

    protected:
         char multiplexed_packet[MAX_MTU_SIZE];

         virtual UInt32 getFullBufferEsId();              
};

#endif // _Multiplexor_H_

//----------------------------------MULTIPLEXOR.CPP----------------------------------------

//#include "Multiplexor.h"

Multiplexor::Multiplexor()
{
   
}

Multiplexor::~Multiplexor()
{
   
}

//------------------------------ALLSTREAMSMUXER.H------------------------------------------

#ifndef _AllStreamsMuxer_H_
#define _AllStreamsMuxer_H_

//#include "Multiplexor.h"

class AllStreamsMuxer : public Multiplexor
{
    public:
         AllStreamsMuxer();
         ~AllStreamsMuxer();

    private:
         UnmuxedPacket multiplex_buffer[MAX_PACKETS_PER_MUX_PACKET];
         UInt32 current_buffer_location;
};

#endif // _AllStreamsMuxer_H_

//-----------------ALLSTREAMSMUXER.CPP-----------------------------------------------------

//#include "AllStreamsMuxer.h"

AllStreamsMuxer::AllStreamsMuxer()
{
    current_buffer_location = 0;
}

AllStreamsMuxer::~AllStreamsMuxer()
{
   
}

Float64 Multiplexor::getPacket(char ** outPacket, int * outPacketLength)
{
    return 5.5;
}

UInt32 Multiplexor::getFullBufferEsId()
{
    return 1;
}
0
 
LVL 3

Expert Comment

by:idt
ID: 10780289
No compiled clean with -Wall, note that I compiled using gcc 3.2 on a Linux 2.4.20
Just compiled with Intel Compiler for Linux ICC v7 also compiled except it noted that parameter "outPacket" was never referenced
Float64 Multiplexor::getPacket(char ** outPacket, int * outPacketLength)

Daniel
0
 
LVL 86

Expert Comment

by:jkr
ID: 10780300
I gave it a try with VC6SP5 here :o)
0
 
LVL 3

Expert Comment

by:idt
ID: 10780354
What do you think jkr, is this some kind of Microsoftism?
I don't do really any Windows environ programming, mostly Linux,SUN, BSD,  some maintenance of Delphi code, but the last MS compiler I used was C700 (circa 1992?).

Stefarg,  what are your includes? SP level?

Daniel
0
 
LVL 86

Expert Comment

by:jkr
ID: 10780368
>>What do you think jkr, is this some kind of Microsoftism?

No, just trying to make clear that the above compiles fine in the same environment and that the error is either in the Compiler  (which would make it a Microsoftism) or in the code that was not shown so far (which I assume :o)
0
 
LVL 12

Assisted Solution

by:stefan73
stefan73 earned 25 total points
ID: 10781407
Hi stefarg,
> constructors not allowed a return type?

If this is what's baffling you - constructors have an implicit return type. It's the class they belong to. Constructors implicitly return "this".

Cheers,
Stefan
0
 
LVL 6

Assisted Solution

by:Mafalda
Mafalda earned 25 total points
ID: 10781856
Seems like a compiler bug.
Your class AllStreamsMuxer is a derived class from class Multiplexor, did you have problems with derived classes in the past ?
Try compiling a simpler case of a derived class and see if you get the same error.
0
 
LVL 1

Author Comment

by:stefarg
ID: 10782033
Thanks for the comments everyone, I'll respond in ascending order. (see subsequent comments)
I'm only back at my computer this morning so that's why I haven't been replying to the messages posted to date.
0
 
LVL 1

Author Comment

by:stefarg
ID: 10782098
Mafalda,
I have only started to implement the subclasses now, AllStreamsMuxer is the first subclass I have written and the Multiplexor superclass worked no problem.

Stefan,
thanks for that but I understand OOP concepts very well, maybe the title I gave was a bit misleading.

idt and jkr,
I think we might have found a serious case of Microsoftism!! Guess what happened this morning when I compiled the project? IT WORKED!! I am very confused as I did not alter the code in any way, it was exactly as above.  I did a clean before I built it so maybe it's possible that a prebuilt file was causing problems?? (Although I did this repeatedly last night...?????)
Anyway, I have made a few changes to the code since so I'll post up what I have so far so that everyone can see it.
(The Multiplexor files have not changed)

----------------------------------AllStreamsMuxer.h-----------------------------------------------
#ifndef _AllStreamsMuxer_H_
#define _AllStreamsMuxer_H_

#include "Multiplexor.h"

class AllStreamsMuxer : public Multiplexor
{
    public:
         AllStreamsMuxer();
         ~AllStreamsMuxer();
             virtual bool insert(QTRTPFile::RTPTrackListEntry* entry);
            virtual Float64 getPacket(char ** outPacket, int * outPacketLength);

      protected:
            virtual UInt32 getFullBufferEsId();

    private:
         UnmuxedPacket multiplex_buffer[MAX_PACKETS_PER_MUX_PACKET];
         UInt32 current_buffer_location;
};

#endif // _AllStreamsMuxer_H_

-------------------------------------AllStreamsMuxer.cpp------------------------------------

#include "AllStreamsMuxer.h"

AllStreamsMuxer::AllStreamsMuxer() : Multiplexor()
{
    current_buffer_location = 0;
}

AllStreamsMuxer::~AllStreamsMuxer()
{
   
}

bool AllStreamsMuxer::insert(QTRTPFile::RTPTrackListEntry* entry)
{
      return false;
}

Float64 AllStreamsMuxer::getPacket(char ** outPacket, int * outPacketLength)
{
    return 5.5;
}

UInt32 AllStreamsMuxer::getFullBufferEsId()
{
    return 1;
}


0
 
LVL 1

Author Comment

by:stefarg
ID: 10782106
Could it be possible that (in true windows style) closing VC++ and restarting the computer could have eliminated the problem, it's the only thing that I can see that is different from last night?
0
 
LVL 86

Expert Comment

by:jkr
ID: 10783340
>>it's the only thing that I can see that is different from last night?

Did you do a 'make clean', or in VC++ terms a "Rebuild All" (i.e. deleting intermediate and precompiled header files)?
0
 
LVL 1

Author Comment

by:stefarg
ID: 10783371
Hey jkr,
I went to "batch build..." and selected "clean" and then "build" which I guess is the same as "rebuild all"
Stef
0
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 10783443
Well, that might explain the difference - once the precompiled header file is deleted, a re-parse is enforced...
0
 
LVL 3

Expert Comment

by:idt
ID: 10783572
Ahh.. well.. now that it's bitten you, you don't have to make that mistake again :)
Nothing like a make clean.

Daniel
0
 
LVL 1

Author Comment

by:stefarg
ID: 10783577
jkr,
Thought it might be something like that, but I did try the same "clean" proceedure last night to no avail.

All,
Well, I think I wrap this up, I think that jkr probably came closest to expalining the problem but I guess we won't find out what exactly what happened because I can't get back to the situation that was causing the error.
Crazy eh, first of all I can't get away from the error, now I can't get back to it to find the cause!!
I think the fairest thing in this situation is to split the results.  Thanks so much for everyone for you help!
Stef
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to understand recursion 12 226
c++ syntax question 9 49
Copy output image from TWindowsMediaPlayer 6 41
Embarcadero C++ builder XE10.1 Berlin TRegistry declaration 1 29
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question