• 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

1 Answer

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

Related questions

0 votes
1 answer 8 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 game 4.6k points
0 votes
1 answer 15 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 game 4.6k points
1 vote
1 answer 23 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 Martin K 6.6k points
1 vote
1 answer 12 views
Problem: Hello guys, I am a novice in the programming world. I&rsquo;ve started learning with the C/C++ language. I&rsquo;ve got a piece of C++ code with two classes. The program is throwing a compile-time error does not name a type I am ... receiveMessage(); vector<Message> *dataMessageList; }; I am looking forward to having a legitimate solution to the problem. Thanks for your kind concern
asked Apr 29 Gavin 15.3k points
1 vote
1 answer 18 views
Problem: I wrote a simple program in c++ and it throws back an error: &ldquo;string does not name a type&rdquo; Find my program snippet below: #include <iostream> #include <fstream> #include <string> using namespace std; class MyClass { private: string description; int test; } Could you please pull me up?
asked Mar 14 Gavin 15.3k points