• Register
1 vote


Hello good people,

I am quite familiar with java programming and willing to figure out a little bit the c++ alongside. So I’ve read the c++ documentation roughly and started coding. You’ll find my sample code below that an error, “c++ incomplete type is not allowed” 

What to do now?

#include<iostream>int main() {
    //declare the array
    int myArray[10];    //initialize and print the array
    for(int i=0;i < 10; i++) {
        myArray[i] = i;
        std::cout << myArray[i] << "\n";


12 7 7
15,250 points

Please log in or register to answer this question.

2 Answers

0 votes


First of all, you need to read the documentation thoroughly instead of roughly before started coding in any programming language. I can see in your code you declared an array myArray as we do in java. There is a little bit difference between java a c++  declaring an array.

When we declare an array in java we do not allocate any memory in it. What it is doing is creating a pointer to the memory taken when the array is then initialized.

On the other hand, when an array is declared in C++, the memory is allocated at the time of declaration, so declaring an empty array is a big no-no because the compiler doesn’t know how much memory to reserve for the array.

This is the key difference between java and c++ in this case.
Keep discovering. Thanks

13 9 6
94,240 points
0 votes
Hi there let me help you to solve this by illustrating an example.

Classes Bat;

Class ball


Void play(Bat&ball);



Class Bat

Ball &ballA;

Float ball posx=800;



Void ball::play(Bat & ball)


ball.ball posx +=10;

Int main()



Here defining  function play requires the complete definition of class Ball.because it can access it's data member in your code.for eg: In module ball.cpp has no access to the definition of class ball which arises an error by the compiler
6 4
2,700 points

Related questions

0 votes
1 answer 13 views
Problem: Each element of the array is a Number object. Is it with triple pointer? (***)
asked Jan 25 sasha 13.2k points
0 votes
1 answer 10 views
Problem: I have been making a code that allows me to use an integer pointer, which stores all the integers that I want until I type the word "end" and then print them, I did it in the following way: #include <iostream> #include <string> using namespace std; int main () ... why does that happen, and how could I correct it so that it allows me to implement the 2 codes at once? Thanks for your help.
asked Dec 25, 2020 sasha 13.2k points
0 votes
1 answer 11 views
Problem: C++ allows you to have pointers to objects. The pointers pointing to objects are referred to as Object Pointers. C++ Declaration and Use of Object Pointers Just like other pointers, the object pointers are declared by placing in front of a object pointer's name. It takes the following general form : class-name &lowast; object-pointer ;
asked Dec 25, 2020 Mashhoodch 9.6k points
0 votes
1 answer 14 views
I know it sounds weird but I wanted to know if there is a possibility in C ++ to write the addresses that a dynamic array saves to a file so that you can read the file and use the saved addresses with other pointers. What would be the way to enter and remove the addresses of the file?
asked Aug 14, 2020 game 4.6k points
0 votes
1 answer 22 views
Problem: I am making a basic text based RPG sorry if my question is stupid because im new to c++. So basically I have a small combat class that i have to link back and forth to from the map class so I had to forward declare my map class and it comes up with the error. BTW sorry there aren't any comments. Here is the error: invalid use of incomplete type class Map
asked Dec 24, 2020 Mashhoodch 9.6k points
0 votes
1 answer 19 views
My problem to solve is this: Make a structure called student, in which you will have the fields: name, age, average and data will be requested from the user of how many students will enter and check which of them has the best average and print it, use pointers. I would ... struct Student {      char name [30];      int age;      average float; } student [nStudents], * studentPointer = student;
asked Aug 14, 2020 game 4.6k points
0 votes
2 answers 8 views
0 votes
1 answer 3 views
Problem Hey, I Am trying to learn how to build a dynamic array of pointer in C++. i know the new operator returns the pointer of the allocated memory int*[ 10 ] of the pointer of array of int. But why we are assigning int**. I am willing to know why we are using that.    int **arr = new int*[10]; 
asked Dec 21, 2020 chris jordan 2.4k points
0 votes
1 answer 42 views
Problem: I just started with C ++, theme pointers and arrays and I had a question with a basic exercise. Sorry for so much code, but I can't find another way to put it in context. I have a trainer structure, one of its fields is a pointer to an array of Pokemon, which ... But it does not print more, that is, it does not continue to travel. Sorry if maybe I am wrong, I am very new to this topic.
asked Dec 4, 2020 sasha 13.2k points
1 vote
1 answer 52 views
Problem: I am in the process of understanding C++ Programming. Currently I am in trouble because of my below C++ program. I have tried to fix it by my own efforts but I am unable to fix the below error. [Error] a function-definition is not allowed here before '{' token ...     mydisplaymenu();     system("pause");     return 0; } I am looking for C++ expert who can help me in fixing above program.
asked May 26, 2020 Martin K 6.6k points