1

I'm trying to write some code in C++ (for OpenFOAM) but I'm getting the error given in the title for this bit of code:

// Copy set
void backup 
(
   const polyMesh& mesh,
   const word& fromName, 
   const topoSet& fromSet,
   const word& toName
)
{
   Info<< "Backing up " << fromName << " into " << toName << endl; 

   topoSet backupSet(mesh, toName, fromSet);

   backupSet.write();
}

The full error is:

faceSet.C:51:18: error: cannot declare variable ‘backupSet’ to be of abstract type ‘Foam::topoSet’ 

The error is in this line:

topoSet backupSet(mesh, toName, fromSet);

From looking this up, I think I understand that topoSet maybe should be declared as a constant but I tried this and it made no difference.

I have a few errors of similar nature but I'm just trying to understand how to fix this one.

Kara
  • 6,115
  • 16
  • 50
  • 57
user3460758
  • 957
  • 7
  • 15
  • 25
  • Ok it's a few hundred lines and I'm not sure which part of it would be the best to include so I can send it as a file somehow? Is there a way to do this? – user3460758 Oct 08 '15 at 10:18
  • No, there is not. You are supposed to construct a [minimal testcase](http://stackoverflow.com/help/mcve), at least in part because this should have been one of your first pre-asking-on-the-internet debugging steps. – Lightness Races in Orbit Oct 08 '15 at 10:49
  • 1
    Not sure how you arrived at "maybe should be declared as a constant" from researching abstract classes! – Lightness Races in Orbit Oct 08 '15 at 10:49
  • @LightnessRacesinOrbit, `topoSet` is actually a class from a framework (OpenFOAM), I don't think you should require converting all framework classes to MVCE for all questions regarding some framework. I don't say that the question is well-researched though. – Petr Oct 08 '15 at 10:58
  • 2
    @Petr: In this case, citing OpenFOAM as an unincluded dependency would be fine. More than anything I was responding in general to the OP's statement _"Ok it's a few hundred lines and I'm not sure which part of it would be the best to include so I can send it as a file somehow"_ as that's simply not how this works. – Lightness Races in Orbit Oct 08 '15 at 10:59
  • @LightnessRacesinOrbit, agreed – Petr Oct 08 '15 at 11:00

2 Answers2

2

You can not create a topoSet instance, because it is an abstract class containing virtual non-implemented methods (maxSize() seems to be one of these). Even if there was no non-implemented (pure virtual) members, creating a topoSet instance would be wrong as you would lose all the information about what was the original type of fromSet and all the data it had above topoSet's (this is akin to slicing).

I think that you should use one of topoSet::New() static functions (named constructors), or if all you need to do is to save it under a different name, then just twice use topoSet::rename() (actually regIOobject::rename()).

Community
  • 1
  • 1
Petr
  • 9,812
  • 1
  • 28
  • 52
0

You cannot use topoSet backupSet; as that would be an attempt to instantiate a topoSet which you can't do as it's abstract.

You need to create an instance of a concrete derived class instead. You'll need to find something appropriate or create it yourself. If we assume that such a thing is called foo then you could use a pointer

topoSet* backupSet = new foo(/*ToDo - parameters*/)

or instantiate directory foo backupSet(/*ToDo - parameters, omit the parentheses if there are no parameters*/).

Bathsheba
  • 231,907
  • 34
  • 361
  • 483