; in function member declaration

C

Carlos Martinez

Hi all:

Must I finalice a function member declaration with ; ?

For example;

class A {
...
public:
myFunc(); //Is this ; necessary
};

I compile my programs using Sun's Forte 6 and linux gcc 3.3.2
In this case (with or without ;) compiles ok with both compilers.

But in the next case:

class DatosUssd {

...

template<typename Tabla> static const Tabla& getRefTabla(Tabla*
DatosUssd::*tabla) {
static const Tabla* nullTabla=0;
if(actual)
return *(actual->*tabla);
else
return static_cast<const Tabla&>(*nullTabla);
}; //this ; gives me an error with sun's Forte 6

public: //Compiler error due to the previous ";" character

...
};

With linux gcc, it compiles ok with or without ;
But with Sun's Forte 6 without ; compiles ok, but with ; compiler gives
me the error:
Error: A declaration was expected instead of "public"

I want to know if finalize function members with ; is a compiler error
or mine.
 
A

Alf P. Steinbach

* Carlos Martinez:
Hi all:

Must I finalice a function member declaration with ; ?

For example;

class A {
...
public:
myFunc(); //Is this ; necessary
};

I compile my programs using Sun's Forte 6 and linux gcc 3.3.2
In this case (with or without ;) compiles ok with both compilers.

But in the next case:

class DatosUssd {

...

template<typename Tabla> static const Tabla& getRefTabla(Tabla*
DatosUssd::*tabla) {
static const Tabla* nullTabla=0;
if(actual)
return *(actual->*tabla);
else
return static_cast<const Tabla&>(*nullTabla);
}; //this ; gives me an error with sun's Forte 6

public: //Compiler error due to the previous ";" character

...
};

With linux gcc, it compiles ok with or without ;
But with Sun's Forte 6 without ; compiles ok, but with ; compiler gives
me the error:
Error: A declaration was expected instead of "public"

I want to know if finalize function members with ; is a compiler error
or mine.

Function declaration: terminating semicolon.

Function definition: no terminating semicolon.

As a simple rule of thumb, never place a semicolon after a right brace
}, except after a class definition, where the semicolon is required.
 
O

Old Wolf

Alf said:
Function declaration: terminating semicolon.

Function definition: no terminating semicolon.

As a simple rule of thumb, never place a semicolon after a right brace
}, except after a class definition, where the semicolon is required.

Semicolons are permitted after function definitions which occur
inside a class definition.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top