Hi,
My compiler is erroring on the following line of a RectangleUser
class:
virtual Rectangle& const getNameDisplayRect(int) const=0;
The error is:
'virtual' can only be used with non-template member functions
The Rectangle class contains no templates and neither does
RectangleUser. I have already double-checked that Rectangle.h is
included in the file RectangleUser.h.
Does anyone know what might be causing this?
Thanks,
cpp 7 1452
cppaddict wrote: My compiler is erroring on the following line of a RectangleUser class:
virtual Rectangle& const getNameDisplayRect(int) const=0;
Write it as
virtual Rectangle const& getNameDisplayRect(int) const = 0;
(your first 'const' is in the wrong place) The error is:
'virtual' can only be used with non-template member functions
The Rectangle class contains no templates and neither does RectangleUser. I have already double-checked that Rectangle.h is included in the file RectangleUser.h.
Does anyone know what might be causing this?
I can only guess that the first 'const' being out of place freaks
the compiler out. Another guess is that 'Rectangle' is somehow
a macro that has some template thing in it, and you don't know of
it because the actual "Rectangle.h" file being included is not
the one you provided, but some system file from some other package
(happened to me once with a header named "data.h" -- very original
name, isn't it?)
Victor
>Write it as virtual Rectangle const& getNameDisplayRect(int) const = 0;
(your first 'const' is in the wrong place)
Victor,
Thanks for your response. Unfortunately, this change didn't help.
As a side note, are you sure the way I have it is wrong? I thought
that "Rectangle& const" means "A reference which cannot be changed
that refers to a rectangle" whereas "Rectangle const&" means "A
reference (which can be changed) that refers to a Rectangle which
cannot be changed". Thus both are legal. Am I wrong here?
Another guess is that 'Rectangle' is somehow a macro that has some template thing in it, and you don't know of it because the actual "Rectangle.h" file being included is not the one you provided, but some system file from some other package (happened to me once with a header named "data.h" -- very original name, isn't it?)
This isn't the case, either. Rectangle.h is a file I wrote, it's an
extremely simple class with no macros.
Any other ideas?
thanks,
cpp
cppaddict wrote: Write it as
virtual Rectangle const& getNameDisplayRect(int) const = 0;
(your first 'const' is in the wrong place)
Victor,
Thanks for your response. Unfortunately, this change didn't help.
As a side note, are you sure the way I have it is wrong? I thought that "Rectangle& const" means "A reference which cannot be changed that refers to a rectangle" whereas "Rectangle const&" means "A reference (which can be changed) that refers to a Rectangle which cannot be changed". Thus both are legal. Am I wrong here?
Yes.
References cannot be changed (according to their nature) and therefore
cannot be cv-qualified. The standard explicitly prohibits qualifiers
for references. Another guess is that 'Rectangle' is somehow a macro that has some template thing in it, and you don't know of it because the actual "Rectangle.h" file being included is not the one you provided, but some system file from some other package (happened to me once with a header named "data.h" -- very original name, isn't it?)
This isn't the case, either. Rectangle.h is a file I wrote, it's an extremely simple class with no macros.
Any other ideas?
Begin eliminating stuff from your program until it compiles. Thus you
will isolate the offending part. Then create a small test program with
it and see if you got it right. If after that you still don't see the
reason why the compiler is complaining, post the small test program and
we can discuss it.
Victor
cppaddict posted: Hi,
My compiler is erroring on the following line of a RectangleUser class:
virtual Rectangle& const getNameDisplayRect(int) const=0;
Try:
const Rectangle& const getNameDisplayRect(int) const = 0;
-JKop
JKop posted: cppaddict posted:
Hi,
My compiler is erroring on the following line of a RectangleUser class:
virtual Rectangle& const getNameDisplayRect(int) const=0;
Try:
const Rectangle& const getNameDisplayRect(int) const = 0; -JKop
TYPO TYPO TYPO
virtual const Rectangle& getNameDisplayRect(int) const = 0;
-JKop References cannot be changed (according to their nature) and therefore cannot be cv-qualified. The standard explicitly prohibits qualifiers for references.
Yes, that makes sense. Thanks. Begin eliminating stuff from your program until it compiles. Thus you will isolate the offending part. Then create a small test program with it and see if you got it right. If after that you still don't see the reason why the compiler is complaining, post the small test program and we can discuss it.
I did this and found that an include being included by one of the
includes I checked brought in the offending part. It was a windows
include and there is a Rectangle function which I think was creating
the problem. In any case, I renamed my class and it works now. Sorry
for the mistake, I thought I'd already ruled out such a conflict.
Thanks again for the guidance,
cpp This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: heted7 |
last post by:
Hi,
Most of the books on C++ say something like this: "A virtual destructor
should be defined if the class contains at least one virtual member
function."
My question is: why is it only for...
|
by: JPRoot |
last post by:
Hi
I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using...
|
by: eric |
last post by:
hello
i'm confused by an example in the book "Effective C++ Third Edition"
and would be grateful for some help. here's the code:
class Person {
public:
Person();
virtual ~Person(); // see...
|
by: v4vijayakumar |
last post by:
Why we need "virtual private member functions"? Why it is not an
(compile time) error?
|
by: Jess |
last post by:
Hello,
If I have a class that has virtual but non-pure declarations, like
class A{
virtual void f();
};
Then is A still an abstract class? Do I have to have "virtual void
f() = 0;"...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |