C++ Compiler error

Hi,

I’m porting a C++ app from QNX4.25 to QNX 6.1 and getting a compiler
error for a private method that is returning a structure declared as
private in the class. The compiler complains at the declaration of the
MyPrivMethod as the following demonstrates:

myclass.h:

class MyClass
{

public:
MyClass() {}
~MyClass() {}

private:

typedef struct
{
int myInt;
float myFloat;
} MY_STRUCT_T;

MY_STRUCT_T MyPrivMethod( int myInt_, float myFloat_ );
};

myclass.cc:

// notice the classname::return_type here, is this not allowed in ANSI
C++???
MyClass::MY_STRUCT_T MyClass::MyPrivMethod( int myInt_, float myFloat_ )
{
MY_STRUCT_T myStruct;

myStruct.myInt = myInt_;
myStruct.myFloat = myFloat_;
return myStruct;
}

Compiler output:
myclass.cc:5: semicolon missing after declaration of `struct
MyClass::MY_STRUCT_T’
cc: /usr/lib/gcc-lib/ntox86/2.95.2/cc1plus error 33

This works under QNX4.25 with the Watcom C++ compiler.

Any ideas?

Thanks in advance,
Rob

There are a couple of things that seem to be not quite right.

  1. typedef is private therefore unless you are a member of the class you
    can’t use it.
  2. Related returning that would be a problem you would have to use class
    scope qualifier before MY_STRUCT_T.

try: MyClass::MY_STRUCT_T MyPrivMethod( int myInt_, float myFloat_ );

gcc is much more strict than Watcom when it comes to ANSI checking and
especially with C++. Watcom C++ compiler is buggy. We changed to Neutrino
because of this.


“Rob Davidson” <rdavidson@softwareremodeling.com> wrote in message
news:3C8FB557.5000901@softwareremodeling.com

Hi,

I’m porting a C++ app from QNX4.25 to QNX 6.1 and getting a compiler
error for a private method that is returning a structure declared as
private in the class. The compiler complains at the declaration of the
MyPrivMethod as the following demonstrates:

myclass.h:

class MyClass
{

public:
MyClass() {}
~MyClass() {}

private:

typedef struct
{
int myInt;
float myFloat;
} MY_STRUCT_T;

MY_STRUCT_T MyPrivMethod( int myInt_, float myFloat_ );
};

myclass.cc:

// notice the classname::return_type here, is this not allowed in ANSI
C++???
MyClass::MY_STRUCT_T MyClass::MyPrivMethod( int myInt_, float myFloat_ )
{
MY_STRUCT_T myStruct;

myStruct.myInt = myInt_;
myStruct.myFloat = myFloat_;
return myStruct;
}

Compiler output:
myclass.cc:5: semicolon missing after declaration of `struct
MyClass::MY_STRUCT_T’
cc: /usr/lib/gcc-lib/ntox86/2.95.2/cc1plus error 33

This works under QNX4.25 with the Watcom C++ compiler.

Any ideas?

Thanks in advance,
Rob

It looks to me like the typedef is not carrying out of the class definition.
If you change the code to this:

class MyClass
{

public:
MyClass() {}
~MyClass() {}

private:

struct my_struct_t
{
int myInt;
float myFloat;
};

struct my_struct_t MyPrivMethod( int myInt_, float myFloat_ );
};

struct MyClass::my_struct_t MyClass::MyPrivMethod( int myInt_, float
myFloat_ )
{
my_struct_t myStruct;

myStruct.myInt = myInt_;
myStruct.myFloat = myFloat_;
return myStruct;
}

It goes just fine. I think you might need to do the typedef outside of the
class for it to work for you.

cheers,

Kris

“Rob Davidson” <rdavidson@softwareremodeling.com> wrote in message
news:3C8FB557.5000901@softwareremodeling.com

Hi,

I’m porting a C++ app from QNX4.25 to QNX 6.1 and getting a compiler
error for a private method that is returning a structure declared as
private in the class. The compiler complains at the declaration of the
MyPrivMethod as the following demonstrates:

myclass.h:

class MyClass
{

public:
MyClass() {}
~MyClass() {}

private:

typedef struct
{
int myInt;
float myFloat;
} MY_STRUCT_T;

MY_STRUCT_T MyPrivMethod( int myInt_, float myFloat_ );
};

myclass.cc:

// notice the classname::return_type here, is this not allowed in ANSI
C++???
MyClass::MY_STRUCT_T MyClass::MyPrivMethod( int myInt_, float myFloat_ )
{
MY_STRUCT_T myStruct;

myStruct.myInt = myInt_;
myStruct.myFloat = myFloat_;
return myStruct;
}

Compiler output:
myclass.cc:5: semicolon missing after declaration of `struct
MyClass::MY_STRUCT_T’
cc: /usr/lib/gcc-lib/ntox86/2.95.2/cc1plus error 33

This works under QNX4.25 with the Watcom C++ compiler.

Any ideas?

Thanks in advance,
Rob

Thanks, that was it. Can’t use the typedef at all within the class
declaration and return it from a method (even if its private as well).
As Tim mentioned before, Watcom allowed this (bug, I guess) but it must
not be ANSI.

Rob


Kris Warkentin wrote:

It looks to me like the typedef is not carrying out of the class definition.
If you change the code to this:

class MyClass
{

public:
MyClass() {}
~MyClass() {}

private:

struct my_struct_t
{
int myInt;
float myFloat;
};

struct my_struct_t MyPrivMethod( int myInt_, float myFloat_ );
};

struct MyClass::my_struct_t MyClass::MyPrivMethod( int myInt_, float
myFloat_ )
{
my_struct_t myStruct;

myStruct.myInt = myInt_;
myStruct.myFloat = myFloat_;
return myStruct;
}

It goes just fine. I think you might need to do the typedef outside of the
class for it to work for you.

cheers,

Kris

“Rob Davidson” <> rdavidson@softwareremodeling.com> > wrote in message
news:> 3C8FB557.5000901@softwareremodeling.com> …

Hi,

I’m porting a C++ app from QNX4.25 to QNX 6.1 and getting a compiler
error for a private method that is returning a structure declared as
private in the class. The compiler complains at the declaration of the
MyPrivMethod as the following demonstrates:

myclass.h:

class MyClass
{

public:
MyClass() {}
~MyClass() {}

private:

typedef struct
{
int myInt;
float myFloat;
} MY_STRUCT_T;

MY_STRUCT_T MyPrivMethod( int myInt_, float myFloat_ );
};

myclass.cc:

// notice the classname::return_type here, is this not allowed in ANSI
C++???
MyClass::MY_STRUCT_T MyClass::MyPrivMethod( int myInt_, float myFloat_ )
{
MY_STRUCT_T myStruct;

myStruct.myInt = myInt_;
myStruct.myFloat = myFloat_;
return myStruct;
}

Compiler output:
myclass.cc:5: semicolon missing after declaration of `struct
MyClass::MY_STRUCT_T’
cc: /usr/lib/gcc-lib/ntox86/2.95.2/cc1plus error 33

This works under QNX4.25 with the Watcom C++ compiler.

Any ideas?

Thanks in advance,
Rob
\

I expect it was probably just a scoping bug in Watcom. The typedef is
probably good as long as you only reference it within the class.

cheers,

Kris

“Rob Davidson” <rdavidson@softwareremodeling.com> wrote in message
news:3C90FF32.7060008@softwareremodeling.com

Thanks, that was it. Can’t use the typedef at all within the class
declaration and return it from a method (even if its private as well).
As Tim mentioned before, Watcom allowed this (bug, I guess) but it must
not be ANSI.

Rob


Kris Warkentin wrote:

It looks to me like the typedef is not carrying out of the class
definition.
If you change the code to this:

class MyClass
{

public:
MyClass() {}
~MyClass() {}

private:

struct my_struct_t
{
int myInt;
float myFloat;
};

struct my_struct_t MyPrivMethod( int myInt_, float myFloat_ );
};

struct MyClass::my_struct_t MyClass::MyPrivMethod( int myInt_, float
myFloat_ )
{
my_struct_t myStruct;

myStruct.myInt = myInt_;
myStruct.myFloat = myFloat_;
return myStruct;
}

It goes just fine. I think you might need to do the typedef outside of
the
class for it to work for you.

cheers,

Kris

“Rob Davidson” <> rdavidson@softwareremodeling.com> > wrote in message
news:> 3C8FB557.5000901@softwareremodeling.com> …

Hi,

I’m porting a C++ app from QNX4.25 to QNX 6.1 and getting a compiler
error for a private method that is returning a structure declared as
private in the class. The compiler complains at the declaration of the
MyPrivMethod as the following demonstrates:

myclass.h:

class MyClass
{

public:
MyClass() {}
~MyClass() {}

private:

typedef struct
{
int myInt;
float myFloat;
} MY_STRUCT_T;

MY_STRUCT_T MyPrivMethod( int myInt_, float myFloat_ );
};

myclass.cc:

// notice the classname::return_type here, is this not allowed in ANSI
C++???
MyClass::MY_STRUCT_T MyClass::MyPrivMethod( int myInt_, float myFloat_ )
{
MY_STRUCT_T myStruct;

myStruct.myInt = myInt_;
myStruct.myFloat = myFloat_;
return myStruct;
}

Compiler output:
myclass.cc:5: semicolon missing after declaration of `struct
MyClass::MY_STRUCT_T’
cc: /usr/lib/gcc-lib/ntox86/2.95.2/cc1plus error 33

This works under QNX4.25 with the Watcom C++ compiler.

Any ideas?

Thanks in advance,
Rob

\

But why would you want to. C++ automatically makes types out of structs.


Bill Caroselli – 1(626) 824-7983
Q-TPS Consulting
QTPS@EarthLink.net


“Kris Warkentin” <kewarken@qnx.com> wrote in message
news:a75lat$ise$2@nntp.qnx.com

I expect it was probably just a scoping bug in Watcom. The typedef is
probably good as long as you only reference it within the class.

cheers,

Kris

“Rob Davidson” <> rdavidson@softwareremodeling.com> > wrote in message
news:> 3C90FF32.7060008@softwareremodeling.com> …
Thanks, that was it. Can’t use the typedef at all within the class
declaration and return it from a method (even if its private as well).
As Tim mentioned before, Watcom allowed this (bug, I guess) but it must
not be ANSI.

Rob


Kris Warkentin wrote:

It looks to me like the typedef is not carrying out of the class
definition.
If you change the code to this:

class MyClass
{

public:
MyClass() {}
~MyClass() {}

private:

struct my_struct_t
{
int myInt;
float myFloat;
};

struct my_struct_t MyPrivMethod( int myInt_, float myFloat_ );
};

struct MyClass::my_struct_t MyClass::MyPrivMethod( int myInt_, float
myFloat_ )
{
my_struct_t myStruct;

myStruct.myInt = myInt_;
myStruct.myFloat = myFloat_;
return myStruct;
}

It goes just fine. I think you might need to do the typedef outside
of
the
class for it to work for you.

cheers,

Kris

“Rob Davidson” <> rdavidson@softwareremodeling.com> > wrote in message
news:> 3C8FB557.5000901@softwareremodeling.com> …

Hi,

I’m porting a C++ app from QNX4.25 to QNX 6.1 and getting a
compiler
error for a private method that is returning a structure declared as
private in the class. The compiler complains at the declaration of
the
MyPrivMethod as the following demonstrates:

myclass.h:

class MyClass
{

public:
MyClass() {}
~MyClass() {}

private:

typedef struct
{
int myInt;
float myFloat;
} MY_STRUCT_T;

MY_STRUCT_T MyPrivMethod( int myInt_, float myFloat_ );
};

myclass.cc:

// notice the classname::return_type here, is this not allowed in ANSI
C++???
MyClass::MY_STRUCT_T MyClass::MyPrivMethod( int myInt_, float
myFloat_ )
{
MY_STRUCT_T myStruct;

myStruct.myInt = myInt_;
myStruct.myFloat = myFloat_;
return myStruct;
}

Compiler output:
myclass.cc:5: semicolon missing after declaration of `struct
MyClass::MY_STRUCT_T’
cc: /usr/lib/gcc-lib/ntox86/2.95.2/cc1plus error 33

This works under QNX4.25 with the Watcom C++ compiler.

Any ideas?

Thanks in advance,
Rob



\

“Bill Caroselli” <qtps@earthlink.net> wrote in
news:a796ct$smj$1@inn.qnx.com:

But why would you want to. C++ automatically makes types out of
structs.

Just as a POI typedef doesn’t “make” types, it’s an alias.

\

Cheers,
Adam

QNX Software Systems Ltd.
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>

So then, are you saying that you specifically don’t want to MAKE a new type?

I guess there could be some usefulness for that. I just can’t think of it.


Bill Caroselli – 1(626) 824-7983
Q-TPS Consulting
QTPS@EarthLink.net


“Adam Mallory” <amallory@qnx.com> wrote in message
news:Xns91D7669D635FBamalloryqnxcom@209.226.137.4

“Bill Caroselli” <> qtps@earthlink.net> > wrote in
news:a796ct$smj$> 1@inn.qnx.com> :

But why would you want to. C++ automatically makes types out of
structs.

Just as a POI typedef doesn’t “make” types, it’s an alias.

\

Cheers,
Adam

QNX Software Systems Ltd.
[ > amallory@qnx.com > ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <> pschon@baste.magibox.net

“Bill Caroselli” <qtps@earthlink.net> wrote in
news:a7bcqg$jhl$1@inn.qnx.com:

So then, are you saying that you specifically don’t want to MAKE a new
type?

I guess there could be some usefulness for that. I just can’t think of
it.

No, what I meant was that “typedef” doesn’t actually create a new type. It
was refenced as doing so in previous posts.

\

Cheers,
Adam

QNX Software Systems Ltd.
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>