473,379 Members | 1,174 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,379 software developers and data experts.

unexpected 'pure virtual function' error

Hi all,

I thought that the 2 following functions would have the same effect;

void first()
{
ClassA a("bla");
anotherFunction(a);
}

void second()
{
anotherFunction(ClassA("bla"));
}

but when using the second alternative I get a 'calling pure virtual
function' error.
Can anybody explain what the difference is between the 2 that would explain
the error?

TIA,

Corno
Aug 5 '06 #1
4 1542
* Corno:
>
I thought that the 2 following functions would have the same effect;

void first()
{
ClassA a("bla");
anotherFunction(a);
}

void second()
{
anotherFunction(ClassA("bla"));
}

but when using the second alternative I get a 'calling pure virtual
function' error.
Can anybody explain what the difference is between the 2
In the second case you're using a temporary.

that would explain the error?
Nope, for that you'll have to post a complete small program that
demonstrates the problem (one possibility, though, is that ClassA's copy
constructor is invoked and calls a pure virtual function).

See the FAQ item "How do I post a question about code that doesn't work
correctly?" currently at <url:
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8>.

--
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?
Aug 5 '06 #2
>Can anybody explain what the difference is between the 2
>
In the second case you're using a temporary.
>that would explain the error?

Nope, for that you'll have to post a complete small program that
demonstrates the problem (one possibility, though, is that ClassA's copy
constructor is invoked and calls a pure virtual function).

See the FAQ item "How do I post a question about code that doesn't work
correctly?"
I see your point about posting the code. However I don't think code is
necessary in this case. The fact that the error I got was specifically a
'pure virtual function call' is not that relevant to me. I trying to
understand how the C++ standard handles temporary variables differently from
named variables. You talk about the copy constructor, are temporary
variables always copied before the statement is executed or is there
anything else the standard has to say about this?

TIA,

Corno
Aug 5 '06 #3
* Corno:
>>Can anybody explain what the difference is between the 2
In the second case you're using a temporary.
>>that would explain the error?
Nope, for that you'll have to post a complete small program that
demonstrates the problem (one possibility, though, is that ClassA's copy
constructor is invoked and calls a pure virtual function).

See the FAQ item "How do I post a question about code that doesn't work
correctly?"

I see your point about posting the code. However I don't think code is
necessary in this case. The fact that the error I got was specifically a
'pure virtual function call' is not that relevant to me. I trying to
understand how the C++ standard handles temporary variables differently from
named variables. You talk about the copy constructor, are temporary
variables always copied before the statement is executed or is there
anything else the standard has to say about this?
(Please do include relevant context).

You're talking about the call

anotherFunction(ClassA("bla"));

No, temporaries are not always copied, and AFAIK in C++0x the temporary
will be guaranteed to /not/ be copied. However, the current standard
allows any number of copies to be made, and requires an accessible copy
constructor of the form T(T const&). Whether a copy is actually made
depends on the compiler, the code, and perhaps the phase of the moon.

Another manifestation of this -- but one that can be regarded as a
Very Nice Feature that as far as I understand it will disappear in C++0x
-- is that you cannot pass a temporary std::auto_ptr to

void foo( std::auto_ptr<Qconst& );

because std::auto_ptr doesn't have a T(T const&) copy constructor, as
required by the current standard.

--
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?
Aug 5 '06 #4
Corno wrote:
>>>Can anybody explain what the difference is between the 2

In the second case you're using a temporary.

>>>that would explain the error?

Nope, for that you'll have to post a complete small program that
demonstrates the problem (one possibility, though, is that ClassA's copy
constructor is invoked and calls a pure virtual function).

See the FAQ item "How do I post a question about code that doesn't work
correctly?"


I see your point about posting the code. However I don't think code is
necessary in this case. The fact that the error I got was specifically a
'pure virtual function call' is not that relevant to me. I trying to
understand how the C++ standard handles temporary variables differently from
named variables. You talk about the copy constructor, are temporary
variables always copied before the statement is executed or is there
anything else the standard has to say about this?
If I'm not mistaken, from your original (lost) posting, you are passing
by value, so the first instance your object will be copied, in the
second, it might not.

With this type of behaviour, you realy should post the smallest snippet
that compiles and exhibits your problem.

--
Ian Collins.
Aug 5 '06 #5

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

Similar topics

9
by: Dario | last post by:
This is a technical C++ post regarding the Microsoft runtime error R6025 Pure Virtual Function Call that sometime occurs in programs compiled with Microsoft Visual C++ 6.0. Please consider the...
11
by: santosh | last post by:
Hello, I was going through the Marshal Cline's C++ FAQ-Lite. I have a doubt regarding section 33.10. Here he is declaring a pure virtual destructor in the base class. And again defining...
37
by: WittyGuy | last post by:
Hi, I wonder the necessity of constructor and destructor in a Abstract Class? Is it really needed? ? Wg http://www.gotw.ca/resources/clcm.htm for info about ]
10
by: PengYu.UT | last post by:
Hi, A pure function is called in the base function constructor. It generate a run time error: "pure virtual method called". My problem is that class A have some derived classes. I want A's...
3
by: Adriano Coser | last post by:
Hi. I'm declaring a property on a base class that is represented by a pure virtual function. Something like this: public: __declspec( property( get=GetWidth ) ) int Width; virtual int...
3
by: Dmitry Prokoptsev | last post by:
Hello, I need to write a class for exceptions which can be thrown, caught, stored and thrown once again. I have written the following code: --- begin --- #include <string> class Exception...
10
by: John Goche | last post by:
Hello, page 202 of Symbian OS Explained by Jo Stichbury states "All virtual functions, public, protected or private, should be exported" then page 203 states "In the rare cases where a...
1
by: jinendrashankar | last post by:
Hi All, 1.Please check this code and its output which is working fine while pure virtual functions( FUN1) prototype of Class CA is different then Class CB Function (FUN1). 2. In Class...
10
by: Rahul | last post by:
Hi, I tried to create a abstract class by having a non-virtual member function as pure, but i got a compilation error saying "only virtual member functions can be pure"... I'm trying to think...
1
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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$) { } ...
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
BarryA
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...
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...

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.