Question

I am getting this error "Use of undeclared Identifier "Main" in Xcode when I try to inherit a class. I am unable to find out why this error is showing up. Please someone help.

My sample code which is failing in Xcode. foo is the base class

foo.h

#ifndef cpp_practice_foo_h
#define cpp_practice_foo_h
class Foo {
public:
    void fooFunc();
};


#endif

foo.cpp

#include "foo.h"
#include<iostream>

using namespace std;

void Foo::fooFunc() {
    cout<< "Hola from Foo!" << endl;
}

main.h

#ifndef cpp_practice_main_h
#define cpp_practice_main_h
#include "foo.h"
class Main :: public Foo
{
public:
    void mainFunc();

};
#endif

main.cpp

#include <iostream>
#include "main.h"
using namespace std;

void Main::mainFunc() {
    cout<< "Hola from Boo" << endl;
}

int main(int argc, const char * argv[])
{
    return 0;
}

The line below in main.h is where the error is showing up.

class Main :: public Foo

Was it helpful?

Solution

Remove second : - change

class Main :: public Foo

to

class Main : public Foo
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top