Sarah
Sarah

Reputation: 2893

C++ error: explicit qualification in declaration

I am trying to work on a tutorial that I wasn't able to finish during class and I'm having a hard time figuring out my errors. I have never seen an explicit qualification error before so I'm not even sure where to start. The only resources I can find online for this kind of error has to do when using namespaces and I don't think I am, at least not explicitly (other than namespace std).

I am sure I'm making a stupid mistake somewhere but these are the errors I'm getting:

View.cpp:12:55: error: explicit qualification in declaration of ‘void promptForAnimals(Animal**, int&)’
View.cpp:53:25: error: explicit qualification in declaration of ‘void printDance(Animal*)’

and this is my promptForAnimals function:

void::promptForAnimals(Animal* barn[], int& numAnimals)
{

  //Animal* barn[MAX_ANIMALS];
  int num;
  string name;

  cout << "How many birds? ";
  cin  >> num; cin.ignore();
  for (int i=0; i<num; i++) {
    cout << "Name " << i+1 << ":  ";
    getline(cin, name);
    barn[numAnimals++] = new Bird(name);
  }

  etc
  }

}

and my printDanceAnimal is empty, just has:

void::printDance(Animal*)
{
}

The errors could very well have to do with my header file, so here it is for good measure:

#ifndef VIEW_H
#define VIEW_H
#include "Animal.h"
#include "defs.h"
#include <iostream>
using namespace std;

class View
{
    public:
        View();
        ~View();
        void promptForAnimals(Animal**, int&);
        void printDance(Animal*);

};

#endif

Upvotes: 1

Views: 8160

Answers (3)

g_d
g_d

Reputation: 707

This error appears when you explicitly specify already opened namespace.

namespace SomeName {
    int SomeName::someFunc() { return 0; } //error
}

I suspect, the empty namespace is the name of the global namespace which is always open, so that is why this kind of error occurs in your case, which is equivalent to that:

int ::someFunc() { return 0; } //error again

Upvotes: 0

Ed Swangren
Ed Swangren

Reputation: 124642

void::promptForAnimals(Animal* barn[], int& numAnimals)

This is wrong. Should be:

void View::promptForAnimals(Animal* barn[], int& numAnimals)
{
    // ...
}

Upvotes: 1

billz
billz

Reputation: 45410

You miss class name in these function definitions:

Update:

void::promptForAnimals(Animal* barn[], int& numAnimals)
void::printDance(Animal*)

To:

void View::promptForAnimals(Animal* barn[], int& numAnimals)
void View::printDance(Animal*)

Upvotes: 3

Related Questions