• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar
  • Skip to footer

Mr.CodeHunter

Programming and Code Solutions

  • Home
  • C++
  • About Us
  • Contact Us
  • Privacy Policy

c++ incomplete type is not allowed [SOLVED]

June 8, 2021 by Admin Leave a Comment

In c++ incomplete type is not allowed error occurs when compiler detect any identifier that is of known data type but definition of it’s is not seen fully.

Below are general errors in c++:

  1. incomplete type is not allowed
  2. stringstream incomplete type is not allowed
  3. ifstream incomplete type is not allowed
C++ Incomplete Type is not allowed
C++ Incomplete Type is not allowed

Always check below point for these type of error:

  1. Have you included proper header file require to use?
  2. Check data type of object is correct ? Many times it require pointer(*) or referee (&) but we are using simple object.
  3. Check definition of class/struct is available ? Possibly have done forward declaration of struct or class but it is not define properly.

c++ incomplete type is not allowed

PROBLEM-1:

#include<iostream>
class A {
public:
	A Parent; //Error: Incomplete type is not allowed
	A(A *ptr) : Parent(*ptr) {

	}
};

SOLUTION-1:

Here object of class can not contain instance of it’s own (A Parent). Because in constructor also we have used it. And when any object create constructor will be called. So Compiler will try recursive call and it will become infinite.

For resolving this error we need to use pointer(*).

#include<iostream>
class A {
public:
	A *Parent;  // Pointer of class
	A(A *ptr) : Parent(ptr) {

	}
};

————————————

PROBLEM-2:

template<class T>
class A
{
public:
	void func(T tObj);
};

void A<class T>::func(T tObj)  // ERROR occurs here
{
	// Do something here
}

SOLUTION-2:

template<class T>
class A
{
public:
	void func(T *tObj); // Solution: Add Pointer
};

void A<class T>::func(T *tObj)  // Solution: Add Pointer
{
	// Do something here
}

c++ incomplete type is not allowed stringstream

Incomplete Type is not allowed due to header missing
Incomplete Type is not allowed due to header missing

PROBLEM:

#include<iostream>
// Require to add header file

int main() {
	std::stringstream obj; // ERROR: incomplete type is not allowed
	return 0;
}

SOLUTION:

Here we have not included sstream header file, so compiler is not able to find std::stringstream and giving incomplete type is not allowed stringstream error. If you declare include file given error will be resolved.

#include<iostream>
#include <sstream> // Require to use std::stringstream 

int main() {
	std::stringstream obj; //RESOLVED by adding header
	return 0;
}

ifstream incomplete type is not allowed

PROBLEM:

#include <iostream>
// require header file

int main()
{
	std::string file;
	std::ifstream ifs{ file };  //ERROR : incomplete type is not allowed

}

SOLUTION:

In c++ for using ifstream, we require #include <fstream> otherwise compiler will not able for find it properly and will give you error of ifstream incomplete type is not allowed.

#include <iostream>
#include <fstream> // Require for using  ifstream 
int main()
{
	std::string file;
	std::ifstream ifs{ file };  //RESOLVED by adding header

}

SEE MORE:

Top 10 C++ IDE – you must try once

Filed Under: All C++, C++

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Search here

Social Media

  • Facebook
  • YouTube

SEE MORE

Fibonacci sequence c++

Fibonacci Sequence c++ is a number sequence which created by sum of previous two numbers. First two number of series are 0 and 1. And then using these two number Fibonacci series is create like 0, 1, (0+1)=1, (1+1)=2, (2+1)=3, (2+3)=5 …etc Displaying Fibonacci Series in C++ ( without recursion) Output: From given output we […]

map c++

C++ Map [Learn by Example]

C++ map is part of Standard Template Library (STL). It is type of Associative container. Map in c++ is used to store unique key and it’s value in data structure. But if you want to store non-unique key value then you can use Multi Map in c++. Let us first understand in detail what is […]

how to copy paste in turbo c++ ?

There are many different C++ IDE are available but still many students are using Turbo c++ for learning c/c++ programming languages. During using Turbo c++ if you are beginner you will be confuse for how to copy and paste in turbo c++ or if you have already copy some content and you want to paste […]

C++

return 0 c++

There are two different scenario return statement is used inside c++ programming. We can use return 0 c++ inside main() function or other user defined functions also. But both have different meanings. return 0 c++ used inside Main function return 0 c++ used inside other user defined function What is meaning of return 0 and […]

C++

c++ expected a declaration [ SOLVED]

When any function or statement is not in scope or we have used wrong syntax then possibly you will get error for c++ expected a declaration in your code. Main reasons for errors are: Incorrect use/declaration inside namespace Statements are added out of scope Required statement need to add inside main/function Solution-1 | Expected a […]

C++

c++ cannot open source file “errno.h” [SOLVED]

Normally you will face c++ cannot open source file “errno.h” in MS Visual Studio c++ projects. These are some solutions to remove opening errors for “errno.h” file. I got the errors to go away by installing the Windows Universal CRT SDK component, which adds support for legacy Windows SDKs. You can install this using the […]

Footer

DISCLAIMER

The information contained on https://www.mrcodehunter.com is for general information purposes only. We assumes no responsibility for errors or omissions in the contents on the Service.

SITEMAP XML

Sitemap

Recent

  • Fibonacci sequence c++
  • C++ Map [Learn by Example]
  • how to copy paste in turbo c++ ?
  • return 0 c++
  • c++ expected a declaration [ SOLVED]

Search

Copyright © 2025 ยท Mr Code Hunter