473,395 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

g++: 'const' qualifiers cannot be applied to...

Hey guys :)

This is a bit of a funny one... We're four guys working on the same project,
everybody using KDevelop and g++ on Linux. Three of us are using Mandrake,
with g++ 3.4.3 and 3.4.1. Project compiles nicely on these three puters.

On the fourth computer, running SUSE 9.3 using KDevelop also, but g++ 3.3.5,
and on the school's Debian server (which is the one that'll actually be
compiling the code eventually), also running g++ 3.3.5, we get a series of
"'const' qualifiers cannot be applied to..." errors when compiling.

This is the start of the .h file of the class that causes the error. The
error refers to the last line, i.e. the constructor declaration:

<code snippet>

#ifndef STDFILEMGR_H
#define STDFILEMGR_H

#include <dirent.h>
#include <fcntl.h>
#include <string>
#include "reporterfunctiontype.typedef"

namespace std
{
class FileManager
{
public:
FileManager(const string &root_, int bufferSize_, const
reporterFunctionType* reporter_);

</code snippet>

And the error (the reference to line 31 is actually the "FileManager..."
line above, I've not included the comment at the top of the .h file here)

<error>

g++ -c filemanager.cpp
In file included from filemanager.cpp:12:
filemanager.h:31: error: `const' qualifiers cannot be applied to `void (
(const
std::string&)'
filemanager.cpp:18: error: `const' qualifiers cannot be applied to `void
()(const std::string&)'
make: *** [filemanager.o] Error 1

</error>

Is this a known problem with this version of the g++ compiler? Or is it just
us doing something silly that the newer version of the g++ compiler accepts
even though it's not correct?

TIA,
Daniel :)
--
Why do cats jump out of windows? Because there's love out there!
Jul 23 '05 #1
17 3959
DanielESFA wrote:
Is this a known problem with this version of the g++ compiler? Or is it
just us doing something silly that the newer version of the g++ compiler
accepts even though it's not correct?


It's us doing something that's not "correct". It was the const on the
function pointer that did it. No problem anymore, sorry ;)

Cheers,
Daniel :)

--
Why do cats jump out of windows? Because there's love out there!
Jul 23 '05 #2
DanielESFA <so*********@il.i.get.viruses.and.spam> wrote in
news:42***********************@news.sunsite.dk:
Hey guys :)

This is a bit of a funny one... We're four guys working on the same
project, everybody using KDevelop and g++ on Linux. Three of us are
using Mandrake, with g++ 3.4.3 and 3.4.1. Project compiles nicely on
these three puters.

On the fourth computer, running SUSE 9.3 using KDevelop also, but g++
3.3.5, and on the school's Debian server (which is the one that'll
actually be compiling the code eventually), also running g++ 3.3.5, we
get a series of "'const' qualifiers cannot be applied to..." errors
when compiling.

This is the start of the .h file of the class that causes the error.
The error refers to the last line, i.e. the constructor declaration:

<code snippet>

#ifndef STDFILEMGR_H
#define STDFILEMGR_H

#include <dirent.h>
#include <fcntl.h>
#include <string>
#include "reporterfunctiontype.typedef"

namespace std
{
class FileManager
{
public:
FileManager(const string &root_, int bufferSize_,
const
reporterFunctionType* reporter_);

</code snippet>


Uh.. you're not supposed to be adding anything to the std namespace....
Jul 23 '05 #3
Andre Kostur wrote:
DanielESFA <so*********@il.i.get.viruses.and.spam> wrote in
news:42***********************@news.sunsite.dk:
Hey guys :)

This is a bit of a funny one... We're four guys working on the same
project, everybody using KDevelop and g++ on Linux. Three of us are
using Mandrake, with g++ 3.4.3 and 3.4.1. Project compiles nicely on
these three puters.

On the fourth computer, running SUSE 9.3 using KDevelop also, but g++
3.3.5, and on the school's Debian server (which is the one that'll
actually be compiling the code eventually), also running g++ 3.3.5, we
get a series of "'const' qualifiers cannot be applied to..." errors
when compiling.

This is the start of the .h file of the class that causes the error.
The error refers to the last line, i.e. the constructor declaration:

<code snippet>

#ifndef STDFILEMGR_H
#define STDFILEMGR_H

#include <dirent.h>
#include <fcntl.h>
#include <string>
#include "reporterfunctiontype.typedef"

namespace std
{
class FileManager
{
public:
FileManager(const string &root_, int bufferSize_,
const
reporterFunctionType* reporter_);

</code snippet>


Uh.. you're not supposed to be adding anything to the std namespace....


LOL :D Forgive me for laughing, but without it you'd have to prepend "std::"
to just about anything you reference! :)
--
Why do cats jump out of windows? Because there's love out there!
Jul 23 '05 #4
DanielESFA wrote:

#ifndef STDFILEMGR_H
#define STDFILEMGR_H

#include <dirent.h>
#include <fcntl.h>
#include <string>
#include "reporterfunctiontype.typedef"

namespace std
{
class FileManager
{
public:
FileManager(const string &root_, int bufferSize_,
const
reporterFunctionType* reporter_);

</code snippet>


Uh.. you're not supposed to be adding anything to the std namespace....


LOL :D Forgive me for laughing, but without it you'd have to prepend "std::"
to just about anything you reference! :)


Which is not a big problem in header files.
For source code files you can use 'using namspace std;'

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #5
DanielESFA wrote:
Andre Kostur wrote:
DanielESFA <so*********@il.i.get.viruses.and.spam> wrote in
news:42***********************@news.sunsite.dk :
Hey guys :)

This is a bit of a funny one... We're four guys working on the same
project, everybody using KDevelop and g++ on Linux. Three of us are
using Mandrake, with g++ 3.4.3 and 3.4.1. Project compiles nicely on
these three puters.

On the fourth computer, running SUSE 9.3 using KDevelop also, but g++
3.3.5, and on the school's Debian server (which is the one that'll
actually be compiling the code eventually), also running g++ 3.3.5, we
get a series of "'const' qualifiers cannot be applied to..." errors
when compiling.

This is the start of the .h file of the class that causes the error.
The error refers to the last line, i.e. the constructor declaration:

<code snippet>

#ifndef STDFILEMGR_H
#define STDFILEMGR_H

#include <dirent.h>
#include <fcntl.h>
#include <string>
#include "reporterfunctiontype.typedef"

namespace std
{
class FileManager
{
public:
FileManager(const string &root_, int bufferSize_,
const
reporterFunctionType* reporter_);

</code snippet>

Uh.. you're not supposed to be adding anything to the std namespace....


LOL :D Forgive me for laughing, but without it you'd have to prepend "std::"
to just about anything you reference! :)


What you are doing is putting YOUR code into the 'std' namespace
(by enclosing it in the 'namespace std {...}' block). That's not
normally done, and can be risky.

Remove the 'namespace std {...}' syntax and replace it with a
'using namespace std;' statement to accomplish what you want, e.g.:

Jul 23 '05 #6
"DanielESFA" <so*********@il.i.get.viruses.and.spam> wrote in message news:42***********************@news.sunsite.dk...
Andre Kostur wrote:
DanielESFA <so*********@il.i.get.viruses.and.spam> wrote in
news:42***********************@news.sunsite.dk:
/.../

<code snippet>

#ifndef STDFILEMGR_H
#define STDFILEMGR_H

#include <dirent.h>
#include <fcntl.h>
#include <string>
#include "reporterfunctiontype.typedef"

namespace std
{
class FileManager
{
public:
FileManager(const string &root_, int bufferSize_,
const
reporterFunctionType* reporter_);

</code snippet>


Uh.. you're not supposed to be adding anything to the std namespace....


LOL :D Forgive me for laughing, but without it you'd have to prepend "std::"
to just about anything you reference! :)


No, you misunderstand. You're *adding your own code* into the "std" namespace. This is not usually done, as "std" is
reserved for the C++ standard library. It certainly runs the risk of confusing someone who had to use your code (as in
"What th'...? I don't recall there being a class called FileManager in the standard library?!?")

If you want to avoid having to prepend std:: to every standard library call you can use:

using namespace std;

However, it is generally frowned upon to use this in a *header* file, since you then enforce the usage on any
compilation unit which includes that header. So for your header files, perhaps you're stuck with prepending a lot of
std::'s ... been there ... get over it.

--
Lionel B

Jul 23 '05 #7
Lionel B wrote:
"DanielESFA" <so*********@il.i.get.viruses.and.spam> wrote in message
news:42***********************@news.sunsite.dk...
Andre Kostur wrote:
> Uh.. you're not supposed to be adding anything to the std namespace....
LOL :D Forgive me for laughing, but without it you'd have to prepend
"std::" to just about anything you reference! :)


No, you misunderstand. You're *adding your own code* into the "std"
namespace. This is not usually done, as "std" is reserved for the C++
standard library. It certainly runs the risk of confusing someone who had
to use your code (as in "What th'...? I don't recall there being a class
called FileManager in the standard library?!?")

If you want to avoid having to prepend std:: to every standard library
call you can use:

using namespace std;


Well, forgive me for shutting up then :D I thought it was the same thing.
Never actually used the "namespace std { //code };" way of doing it until
using kdevelop which automatically does it when I create classes. Guess
what it means by the namespace question is which namespace I'd like to add
it to... Ahem... Silly me. Makes a lot of sense, really. Apologies for
laughing :/ And thanks to Andre for pointing it out. And thanks to the rest
of you for correcting me :) Better change the code before we hand in our
project, then ;) Hehe!
However, it is generally frowned upon to use this in a *header* file,
since you then enforce the usage on any
compilation unit which includes that header.
You mean that by including "using namespace std" in the header, I'd not only
have to be careful myself of name collisions, but other people using my
class would have to, too?
So for your header files,
perhaps you're stuck with prepending a lot of std::'s ... been there ...
get over it.


--
Why do cats jump out of windows? Because there's love out there!
Jul 23 '05 #8
Larry I Smith wrote:
DanielESFA wrote:
Andre Kostur wrote:
Uh.. you're not supposed to be adding anything to the std namespace....


LOL :D Forgive me for laughing, but without it you'd have to prepend
"std::" to just about anything you reference! :)


What you are doing is putting YOUR code into the 'std' namespace
(by enclosing it in the 'namespace std {...}' block). That's not
normally done, and can be risky.

Remove the 'namespace std {...}' syntax and replace it with a
'using namespace std;' statement to accomplish what you want, e.g.:


Thanks, I will :) Was the old way of doing it, going back now ;)

Daniel

--
Why do cats jump out of windows? Because there's love out there!
Jul 23 '05 #9
Karl Heinz Buchegger wrote:
DanielESFA wrote:

LOL :D Forgive me for laughing, but without it you'd have to prepend
"std::" to just about anything you reference! :)


Which is not a big problem in header files.
For source code files you can use 'using namspace std;'


Howcome it's okay in the cpp file but not in the h file? Is that because the
cpp file's scope is strictly within the class, so the std namespace would
be encapsuled here?

--
Why do cats jump out of windows? Because there's love out there!
Jul 23 '05 #10
DanielESFA <so*********@il.i.get.viruses.and.spam> wrote in
news:42***********************@news.sunsite.dk:
Lionel B wrote:

However, it is generally frowned upon to use this in a *header* file,
since you then enforce the usage on any
compilation unit which includes that header.


You mean that by including "using namespace std" in the header, I'd
not only have to be careful myself of name collisions, but other
people using my class would have to, too?


Yep... you'd be forcing your choice to loft all of std:: into the global
namespace onto everyone who #include's your header file.

See item #59 in "C++ Coding Standards" by Herb Sutter and Andrei
Alexandrescu. Nutshell, don't use a "using" statement before any
#include.... (and since your header file can't know what other header files
may have been #included before you, don't use "using"s in a header file at
all....)
Jul 23 '05 #11
DanielESFA <so*********@il.i.get.viruses.and.spam> wrote in
news:42***********************@news.sunsite.dk:
Karl Heinz Buchegger wrote:
DanielESFA wrote:

LOL :D Forgive me for laughing, but without it you'd have to prepend
"std::" to just about anything you reference! :)


Which is not a big problem in header files.
For source code files you can use 'using namspace std;'


Howcome it's okay in the cpp file but not in the h file? Is that
because the cpp file's scope is strictly within the class, so the std
namespace would be encapsuled here?


If it's only in your cpp file, then only _you_ need to deal with the
potential name clashes. By putting in a header file, then you, and
everbody who includes your header file would have to deal with it....
Jul 23 '05 #12
DanielESFA wrote:
namespace std
{
class FileManager
{
public:
FileManager(const string &root_, int bufferSize_, const
reporterFunctionType* reporter_);

</code snippet>

Don't ever place your facilities in the namespace std. Use "using std::" and "using
namespace std" statements, and place your facilities (both declarations and definitions)
inside a new namespace of yours:
namespace FileManagerApp
{
using std::cout;
using std::endl;

// ...
}
or
namespace FileManagerApp
{
using namespace std;

// ...
}

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #13
Larry I Smith wrote:
What you are doing is putting YOUR code into the 'std' namespace
(by enclosing it in the 'namespace std {...}' block). That's not
normally done, and can be risky.

Remove the 'namespace std {...}' syntax and replace it with a
'using namespace std;' statement to accomplish what you want, e.g.:

.
.
.
#include "reporterfunctiontype.typedef"

using namespace std;

class FileManager
{
...
}
.
.
.

This is not suitable for header files either. The usual (recommended) approach is to place
our own facilities in a new application namespace. Also this enables extension, we can
even use our application as a library/component of another application in the future.


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #14
Lionel B wrote:
However, it is generally frowned upon to use this in a *header* file, since you then enforce the usage on any
compilation unit which includes that header. So for your header files, perhaps you're stuck with prepending a lot of
std::'s ... been there ... get over it.

using std:: statements in the global scope inside a header file, has the same global
namespace pollution effects. See my other messages on the recommended way. :-)


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #15
Ioannis Vranos wrote:
Larry I Smith wrote:
What you are doing is putting YOUR code into the 'std' namespace
(by enclosing it in the 'namespace std {...}' block). That's not
normally done, and can be risky.

Remove the 'namespace std {...}' syntax and replace it with a
'using namespace std;' statement to accomplish what you want, e.g.:

.
.
.
#include "reporterfunctiontype.typedef"

using namespace std;

class FileManager
{
...
}
.
.
.

This is not suitable for header files either. The usual (recommended)
approach is to place our own facilities in a new application namespace.
Also this enables extension, we can even use our application as a
library/component of another application in the future.


Yes, in my haste I failed to note that we were dealing with a header.
Sorry.

Regards,
Larry

--
Anti-spam address, change each 'X' to '.' to reply directly.
Jul 23 '05 #16
Larry I Smith wrote:
This is not suitable for header files either. The usual (recommended)
approach is to place our own facilities in a new application namespace.
Also this enables extension, we can even use our application as a
library/component of another application in the future.

Yes, in my haste I failed to note that we were dealing with a header.
Sorry.

Actually we should make what I mentioned for both our header and implementation files. In
all cases, we should place our own facilities inside a new application namespace. And then
we can use both "using std::" and "using namespace std" statements inside our application
namespace. But in general, we should still stick with local std:: statements in header
files, even inside in our namespace.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #17
Ioannis Vranos wrote:
Don't ever place your facilities in the namespace std. Use "using std::"
and "using namespace std" statements, and place your facilities (both
declarations and definitions) inside a new namespace of yours:
namespace FileManagerApp
{
using std::cout;
using std::endl;

// ...
}
or
namespace FileManagerApp
{
using namespace std;

// ...
}


Thank you for that tip! This will be the way I'll do it from now on :)

--
Why do cats jump out of windows? Because there's love out there!
Jul 23 '05 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jim West | last post by:
Could someone please explain to me why the code segment class FOO { public: double *begin(); }; void bar(const FOO &foo) { foo.begin(); }
2
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
10
by: dwaach | last post by:
Hi, I am trying to compile the following program, #include <iostream> using namespace std; typedef char* CHAR; typedef const CHAR CCHAR;
20
by: Snis Pilbor | last post by:
Whats the point of making functions which take arguments of a form like "const char *x"? It appears that this has no effect on the function actually working and doing its job, ie, if the function...
16
by: hzmonte | last post by:
Correct me if I am wrong, declaring formal parameters of functions as const, if they should not be/is not changed, has 2 benefits; 1. It tells the program that calls this function that the...
10
by: d3x0xr | last post by:
---- Section 1 ---- ------ x.c int main( void ) { char **a; char const *const *b; b = a; // line(9)
0
by: d3x0xr | last post by:
Heh, spelled out in black and white even :) Const is useles... do NOT follow the path of considering any data consatant, because in time, you will have references to it that C does not handle,...
4
by: lovecreatesbea... | last post by:
Gcc only gives out a warning: `assignment discards qualifiers from pointer target type' against code such as following: $ type a.c int main(void) { const char *pc; char *p = pc;
10
by: Stephen Howe | last post by:
Hi Just going over some grey areas in my knowledge in C++: 1) If I have const int SomeConst = 1; in a header file, it is global, and it is included in multiple translations units, but it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.