473,413 Members | 2,043 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,413 software developers and data experts.

Code still compile when there is a mis-match in .h and .cpp

Hi,

In my .h file, I declare this:
class A{
public:
void f1 (const B* bPtr);
};

But In my .cpp, I do this:

void A::f1(B* bPtr) {
//....
}

My question is I miss 'const' in my implementation (.cpp), why the
code still compile?

Feb 21 '07 #1
4 1287
* yi*****@gmail.com:
Hi,

In my .h file, I declare this:
class A{
public:
void f1 (const B* bPtr);
};

But In my .cpp, I do this:

void A::f1(B* bPtr) {
//....
}

My question is I miss 'const' in my implementation (.cpp), why the
code still compile?
If you had the 'const' in a slightly different place, the compiler would
have been right.

As it is, perhaps there are options you can turn on to make it more
standard-conforming.

Or, use some other compiler.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Feb 21 '07 #2
On 21 Feb, 17:19, "ying...@gmail.com" <ying...@gmail.comwrote:
Hi,

In my .h file, I declare this:
class A{
public:
void f1 (const B* bPtr);

};

But In my .cpp, I do this:

void A::f1(B* bPtr) {
//....

}

My question is I miss 'const' in my implementation (.cpp), why the
code still compile?
It shouldn't compile, for exactly the reason you suggest - unless, of
course, your class A *also* contains an overload of f1 declared as
void f1 (B* bPtr);
in the class.

If not, maybe something else in your code is causing your confusion.
You've posted a snippet that I can't directly compile so I don't know
what else is in your code. See posting guidelines at
http://www.parashift.com/c++-faq-lit...t.html#faq-5.8

Try this complete program. Does it compile for you? What compiler are
you using?

class B {};

class A{
public:
void f1 (const B* bPtr);
};
void A::f1(B* bPtr) {}

int main() {}

Gavin Deane

Feb 21 '07 #3
On Feb 21, 11:25 am, "Alf P. Steinbach" <a...@start.nowrote:
* ying...@gmail.com:
Hi,
In my .h file, I declare this:
class A{
public:
void f1 (const B* bPtr);
};
But In my .cpp, I do this:
void A::f1(B* bPtr) {
//....
}
My question is I miss 'const' in my implementation (.cpp), why the
code still compile?

If you had the 'const' in a slightly different place, the compiler would
have been right.

As it is, perhaps there are options you can turn on to make it more
standard-conforming.

Or, use some other compiler.
Thanks. Can you please tell me what is the place where the compiler
would have been right?
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Feb 21 '07 #4
* yi*****@gmail.com:
On Feb 21, 11:25 am, "Alf P. Steinbach" <a...@start.nowrote:
>* ying...@gmail.com:
>>Hi,
In my .h file, I declare this:
class A{
public:
void f1 (const B* bPtr);
};
But In my .cpp, I do this:
void A::f1(B* bPtr) {
//....
}
My question is I miss 'const' in my implementation (.cpp), why the
code still compile?
If you had the 'const' in a slightly different place, the compiler would
have been right.

As it is, perhaps there are options you can turn on to make it more
standard-conforming.

Or, use some other compiler.
Thanks. Can you please tell me what is the place where the compiler
would have been right?
Why? I have the feeling that the original question was contrived. That
you simply /got the question wrong/.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Feb 21 '07 #5

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

Similar topics

2
by: jojocrazy | last post by:
I'm definately not a regexp wiz.... need some suggestions here: grab PHP_SELF, strip the end filename off and the 2 directories preceeding it... This is what I've come up with so far, except...
242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
1
by: RPS | last post by:
Hi, I'm using CYGWIN g++. I'm having trouble making an API call the WindowFromPoint function. Here is my code. FILE: t.cc #include <windows.h> int main () {
4
by: Henro V | last post by:
Private Sub Form_Current() If Form.NewRecord = True Then If DCount("Id", "Urenregistratie") = 4026 Then MsgBox "Sorry, deze registratie gaat maar tot en met 31-12-2004", vbOKOnly, "Toevoegen niet...
1
by: JMUApache | last post by:
Where can I download some C# MIS System Source code. Any help would be appreciate! Thanks //Chen Hui
29
by: Gernot Frisch | last post by:
Hi, I have no clue. - I want to align the red, green, blue boxes in one line - red,green,blue must be 45px high - red (center) must be as wide as possible - yellow must start exactly below...
14
by: Schraalhans Keukenmeester | last post by:
I am building a default sheet for my linux-related pages. Since many linux users still rely on/prefer viewing textmode and unstyled content I try to stick to the correct html tags to pertain good...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
1
by: Randell D. | last post by:
Folks, I consider myself well versed with Apache 1.3 and PHP4 - I found drupal and wanted to try it out - I had problems getting it working with Apache2/PHP5/MySQL5 so I downgraded... Note: I...
14
by: 2005 | last post by:
Would it suppress errors? Is he trying to hide errors in his code?
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.