Coding⏱️ 2 min read📅 2026-05-30

How to Fix: error: request for member '..' in '..' which is of non-class type

The error occurs because the constructor that takes no arguments is not explicitly declared as a constructor, so it's treated as a function. To fix this, add an explicit constructor declaration for the default constructor.

Quick Answer: Add a constructor declaration like Foo() {} to explicitly declare the default constructor.

The error 'request for member '..' in '..' which is of non-class type' occurs when you attempt to access a member function or variable on an object that has not been initialized. In your case, this happens because the default constructor `Foo()` does not initialize the object properly, resulting in a null pointer exception.

🛠️ Step-by-Step Verified Fixes

Method 1: Constructor Initialization

  1. Step 1: Initialize the object using the default constructor `Foo() {}` to set the object's state to its default values. You can do this by calling it like so: `Foo foo2(); foo2 = Foo();

Method 2: Constructor Overload with Default Argument

  1. Step 1: Add a default argument to the constructor that takes no arguments, like so: `Foo() : bar(0) {}`. This initializes the object's state with default values.

🎯 Final Words

By following these steps, you can resolve the error 'request for member '..' in '..' which is of non-class type' and ensure that your objects are initialized properly.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions