Christopher Lee
Christopher Lee

Reputation: 167

error: ‘class::class()’ is private within this context

I've seen a few answers on this topic, but to my knowledge they don't quite answer the problem I'm getting. Here is my paraphrased code:

using namespace std;

class classname
{
private:
    int foo;

    classname();
};

classname::classname()
{
    //dostuff
}
  
int main(){
    classname arr[5];
}

The code errors:

error: ‘classname::classname()’ is private within this context

My best guess is that private: bled into my constructor definition. How do I stop this?

Upvotes: 1

Views: 3107

Answers (1)

Chase Jones
Chase Jones

Reputation: 131

Everything after private: is marked as private until the end of the class is reached or another visibility token. Put your function above the private: or put a public: before the function declaration.

Upvotes: 1

Related Questions