CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

C question

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 4, 2008, 05:59
Default Dragos, I did followed thr
  #21
kar
Senior Member
 
Kārlis Repsons
Join Date: Mar 2009
Location: Latvia
Posts: 111
Rep Power: 17
kar is on a distinguished road
Dragos,

I did followed through code, but did you read previous posts - the thing is: when I try to declare my own base and derived class with operator= in base class, operator= isn't accessible for object of class deriv if there is no forwarding in deriv class's declaration. Can't see such forwarding in class GeometricBoundaryField (and others) - can you help?

K.
kar is offline   Reply With Quote

Old   March 4, 2008, 09:59
Default Indeed you're right, and it wa
  #22
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
Indeed you're right, and it was my mistake. I don't see why in your code it is possible to call int i = 10; d.se(i); but not int i = 10; d.operator=(10); nor int i = 10; d = i;
...promise to look into it!

Dragos
dmoroian is offline   Reply With Quote

Old   March 5, 2008, 08:47
Default Ok, I think I have an answer!
  #23
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
Ok, I think I have an answer!
Among other free on-line c++ book, there is also Thinking in C++ by Bruce Eckel. It specifies, and I quote:
Quote:
Except for the assignment operator, operators are automatically inherited into a derived class.
Which means that, you just picked an unfortunate example, trying to overload operator=. If instead of operator=, you would have chosen any other operator, like operator[], then everything would go smoothly.

I've just tried it, and it works!

I hope this is useful,
Dragos
dmoroian is offline   Reply With Quote

Old   March 5, 2008, 08:59
Default Thank you! I'll take a look at
  #24
kar
Senior Member
 
Kārlis Repsons
Join Date: Mar 2009
Location: Latvia
Posts: 111
Rep Power: 17
kar is on a distinguished road
Thank you! I'll take a look at that book
kar is offline   Reply With Quote

Old   May 19, 2008, 14:27
Default Hmm, may I ask about virtual f
  #25
kar
Senior Member
 
Kārlis Repsons
Join Date: Mar 2009
Location: Latvia
Posts: 111
Rep Power: 17
kar is on a distinguished road
Hmm, may I ask about virtual functions and inheritance?

#include <iostream>

using namespace std;

class base1
{
public:
bool use(bool y) {return x(y);}
virtual bool x(bool y) = 0;
};

class base2
{
public:
bool x(bool y) {return !y;}
};

class deriv:
public base1, public base2
{
// whatever
};

int main( int c, char ** a)
{
deriv d;
if (!d.use(1)) cout << "yes";
return 1;
}

But it is "no", because compiler output is:

virtinh.cpp: In function 'int main(int, char**)':
virtinh.cpp:26: error: cannot declare variable 'd' to be of abstract type 'deriv'
virtinh.cpp:20: note: because the following virtual functions are pure within 'deriv':
virtinh.cpp:9: note: virtual bool base1::x(bool)

So is it impossible to "merge" an abstract class with definitions of virtual functions, that reside in another base class similarly to example below?
kar is offline   Reply With Quote

Old   May 19, 2008, 20:51
Default may be the pure virtual functi
  #26
Senior Member
 
su_junwei's Avatar
 
su junwei
Join Date: Mar 2009
Location: Xi'an China
Posts: 151
Rep Power: 20
su_junwei is on a distinguished road
Send a message via MSN to su_junwei
may be the pure virtual function "virtual bool x(bool y) = 0; " in class "base1" should be defined definitely.
Su Junwei
su_junwei is offline   Reply With Quote

Old   May 20, 2008, 07:05
Default That is a whole point of my qu
  #27
kar
Senior Member
 
Kārlis Repsons
Join Date: Mar 2009
Location: Latvia
Posts: 111
Rep Power: 17
kar is on a distinguished road
That is a whole point of my question, that virtual bool x(bool y) = 0; and I want it to be called from use(..) through deriv d!
kar is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question concerning VOF Flora FLUENT 2 July 9, 2007 10:50
question about LES gino briganti FLUENT 3 June 27, 2005 07:05
A question zhhuang Siemens 0 April 29, 2003 02:44
The question about Y+ rambol CFX 2 November 7, 2002 10:40
Another UDF question Christian FLUENT 7 July 23, 2002 05:19


All times are GMT -4. The time now is 10:20.