johnbakers
johnbakers

Reputation: 24750

How to return a pointer that uses a custom constructor

I'm getting this error:

Expected '(' for function-style cast or type construction

On the second line:

struct OpenALInterface * CreateOpenALInterface(int numLoadedSounds, int numPlayingSounds){
   return new IOS_OpenAL(int numLoadedSounds, int numPlayingSounds); //ERROR ABOVE
   //    return new IOS_OpenAL();  //this works fine, no error
 };

Class has this:

class IOS_OpenAL: public OpenALInterface{

 public:

IOS_OpenAL(int numLoadedSounds, int numPlayingSounds){
    //do stuff
   };

  //    IOS_OpenAL(){}; //works

What exactly is this error referring to? It looks like a syntax error.

The base class is abstract with no constructors. Is that the issue? Can a subclass override or have its own constructor not in the base class?

Upvotes: 1

Views: 91

Answers (2)

weekens
weekens

Reputation: 8292

Did you mean this:

struct OpenALInterface * CreateOpenALInterface(int numLoadedSounds, int numPlayingSounds){
   return new IOS_OpenAL(numLoadedSounds, numPlayingSounds);
};

Upvotes: 3

dspeyer
dspeyer

Reputation: 3026

return new IOS_OpenAL(int numLoadedSounds, int numPlayingSounds);

should be

return new IOS_OpenAL(numLoadedSounds, numPlayingSounds);

The error happens because the compiler sees those "int" tokens and thinks you're trying to cast something to an int, but you're not.

Upvotes: 3

Related Questions