Variable has incomplete type ошибка

First, the reason that you are seeing the error «incomplete type void» is because you have a semicolon that is essentially ending the function definition of your Menu function. In layman’s terms, you have not completely finished defining your function.

Second, by convention, a simple C++ program like you have written should follow the following code layout.

  1. Program Includes
  2. Function Prototypes
  3. Main Function
  4. Function Definitions

You have the correct ordering of your program except that you need to end the main function before beginning your function definitions.

So you should have:

main()
{
  ...
}//End main function

void menu()
{
  ...
}

Another thing I notice, is that the parameters you have given your main function are usually used if you are going to be taking input from the command line. Since you are asking for input from the user in your program, you should change the way you have declared your main function.

Instead of using

int main(int argc, const char * argv[])
{
  ...
}

Declare it like this

int main()
{
  ...
}

Before I can answer your last question, you need to build functionality to handle the users input. This can be done with a switch case statement. If you need information about using the switch case statement in C++, you can find a great explanation at http://www.cplusplus.com/doc/tutorial/control/

One way that you could implement this switch statement is to place the calls to the functions to calculate the slope and length of a line in your switch case. You will need to change one thing about the parameters of your menu function if you do it this way. You will need to pass the values of the coordinates to the menu function as well. For example,

void Menu (MenuNum, X1, X2, Y1, Y2)
{
    cout << "To calculate the slope of the line, enter 1 " << endl;
    cout << "To calculate the length of the line, enter 2" << endl;
    cout << "To calculate the length and slope of the line, enter 3" << endl;
    cin >> MenuNum;

    switch(MenuNume)
    {
      case 1:
      {
        //call calculate slope function
        break;
      }
      case 2:
      {
        //call calculate length function
        break;
      }
      case 3:
      {
        //call both calculate slope and calculate length functions
        break;
      }
      default:
      {
         cout << "Please enter a correct value." << endl;
      }
    }

}

I think that answers all of your questions. Hope this helps!

@YanlongLi

I installed YCM using commands below,

mkdir ~/.vim && cd ~/.vim 
git init
git remote add YouCompleteMe git@github.com:Valloric/YouCompleteMe.git
git pull YouCompleteMe master
git submodule update --init --recursive
./install.py --clang-completer --system-libclang --system-boost

but when I write C++ code but with an error variable has incomplete type 'std::string' (aka 'basic_string<char, char_traits<char>, allocator<char> >') at No.5 line.

code is below

     1  #include <iostream>
     2  #include <string>
     3  
     4  int main() {
     5    std::string str("");
     6    return 0;
     7  }
     8  

Even when I install with ./install.py --clang-completer, problem stills.

My configuration of YCM

let g:ycm_auto_trigger = 1
let g:ycm_complete_in_strings = 1
let g:ycm_echo_current_diagnostic=1
let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'

global extra conf with flags:

flags = [
'-Wall',
'-std=c++11',
'-stdlib=libc++',
'-x',
'c++',
'-I',
'.',
'-isystem', '/usr/include/c++/v1'
]

I couldn’t figure out which part I had it wrong.

@puremourning

What platform are you on?

Is there a specific reason why you’re adding -stdlib=libc++ ?

does the file build when you manually build it with clang++ or gcc ?

Basically, there’s nothing wrong with your code, or your flags, and if i use them as follows:

.ycm_extra_conf.py

def FlagsForFile( file_name, **kwargs ):
    return {
        'flags': [
            '-Wall',
            '-std=c++11',
            '-stdlib=libc++',
            '-x',
            'c++',
            '-I',
            '.',
            '-isystem', '/usr/include/c++/v1'
            ],
        'do_cache': True
        }

test.cc

 #include <iostream>
 #include <string>

int main() {
    std::string str("");
    return 0;
}

It works fine. So i’m assuming this a problem with your system setup, not with YCM or ycmd, so i’m closing as per CONTRIBUTING.md

@fatfatson

@puremourning
i have this problem too..
macos10.11 vim7.4 ycm-latest
either system clang or ycm downloaded

beside the incomplete type ‘std::string’ , there’s another problem said stdarg.h not found.
but it’s very strange:
if i remove the first include of iostream
the incomplete type error disappears, and the completion works ok.

i think there must be something wrong with ycm’s clang, the above code could be built and run by system’s clang++ correctly.

@fatfatson

@Valloric
some pre version is ok, but the latest one is break in my new macbookpro.

@cypres

Removing -stdlib=libc++ does not help. This should be reopened, after upgrading YCM it starts spitting out these weird errors.

@puremourning

You need to add the system include paths. Check the FAQ for something like clang -v -E -x c++ -

@cypres

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/6.1.0/include had changed to /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/include. Sorry for the inconvenience 😔

@mantognini

@duedal Thanks! I was experiencing the same issue since a recent update; this fixed the problem for me. :-)

@seekerFactory

Have a similar issue with ycm showing these messages and haven’t figured them out yet for a satisfactory solution yet. I keep arriving at them as my system(OSX 10.11) now, on regular intervals after some tools updates or upgrade changes the default compilers :( and always end up with multiple binaries(system default or from Homebrew) in path and defaults creating issues sometimes. After reading other threads tried compiling these programs with other compilers and still ycm showing message they have tend to produce proper binaries, not a decent solution though.
As @puremourning suggested its a setup issue.

@arrufat

I had the same problem on Linux using system clang. I solved it by adding the following include line to the .ycm_extra_conf.py:
‘-I’, ‘/usr/lib/clang/3.7.1/include/’,
I will need to update the version number whenever clang is updated, though… So no completely satisfactory…

@guoxiao

I had the same problem on Linux. I checked the output of clang -v -E -x c++ - and found the order of includes differs with the .ycm_extra_conf.py. As long as I moved /usr/include to after /usr/include/c++/6.0.0 the problem was gone.

@crapp

I never had this problem. Worked on my project two days ago. Today I started vim with YouCompleteMe again and had lots of errors as well as the one mentioned here. I just upgraded from gcc 5.3 to gcc 6.1 so maybe this is related. But it was always enough to add /usr/include and /usr/local/include to my .ycm_extra_conf.py. I extracted the include path with clang -v -E -x c++ - and had to add all of them. This means I have to change these includes whenever gcc or clang will be updated.

@puremourning

I think you’re saying that you changed your compilation environment and had to adjust your compilation flags. I’m not sure what more ycmd could do here.

On 11 May 2016, at 10:34, Christian Rapp notifications@github.com wrote:

I never had this problem. Worked on my project two days ago. Today I started vim with YouCompleteMe again and had lots of errors as well as the one mentioned here. I just upgraded from gcc 5.3 to gcc 6.1 so maybe this is related. But it was always enough to add /usr/include and /usr/local/include to my .ycm_extra_conf.py. I extracted the include path with clang -v -E -x c++ — and had to add all of them. This means I have to change these includes whenever gcc or clang will be updated.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub

@crapp

Well but before the latest gcc Update I had not to specify any other include directories other than /usr/include and /usr/local/include. I am using archlinux so I get updates for all kind of things quite often. I did not have any problems with any gcc update before 6.1 so I wonder why I now have to add all those include directories.

@tgy

@crapp arch linux too, i have the same issue after upgrading gcc. did you find a better way than adding all those flags?

@crapp

@tgy Unfortunately not. I have to admit I didn’t invest much time so far investigating the issue much further.

@viohex

‘-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1’,
‘-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/include’,
‘-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include’,
‘-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include’,
‘-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks’,

I add these path which print by «clang -v -E -x c++ — » into flags,the error disappear.

@github-actions
github-actions
bot

locked as resolved and limited conversation to collaborators

May 21, 2021

Hello I’m fresh into c++ and I’m really struggling with this error. I’m tasked to have all the outputs for my values of area, perimeter, and diagonal in a display function. I created one and am trying to invoke the function within my main file but I keep encountering the error in the title.

What exactly does the error mean in this situation and how should I go about fixing it? Thanks in advance.

The display function is being called in int main() on line 43.
The display function was created on line 72.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <iomanip> //using setprecision(1)
#include <math.h>
using namespace std;
 
//functions
double findArea(double sideOne, double sideTwo);
double findPerimeter(double sideOne, double sideTwo);
double findDiagonal(double sideOne, double sideTwo);
void display(double sideOne, double sideTwo, double area, double perimeter, double diagonal);
 
//Main
int main()
{   //Variables
    double sideOne, sideTwo;
 
    //Gathering the number for boths sides from the user
    cout << "Please enter the length of side one." << endl;
    cin >> sideOne;
 
    cout << "nPlease enter the length of the side two." << endl;
    cin >> sideTwo;
 
    //Validating that the values are greater than zero
    if (sideOne <=0 || sideTwo <= 0)
    {
        cout << "Both values for the length need to be greater than zero." << endl;
        exit(0);
    }
 
    //setting precision to one decimal place
    cout << fixed << setprecision(1);
    // Declaring the variable area and invoking the findArea function to calculate and assign the value
    double area = findArea(sideOne,sideTwo);
 
    //Invoking the perimeter function and outputting value
    double perimeter = findPerimeter(sideOne,sideTwo);
 
    //Invoking diagnal function
    double diagonal = findDiagonal(sideOne,sideTwo);
 
 
    void display(area, perimeter, diagonal);
    {
        cout << area << endl; // this line is just here for testing. Definitely wrong.
    }
    return 0;
}
 
//Calculating Area
double findArea( double sideOne, double sideTwo)
{
    double area = sideOne * sideTwo;
    return area;
}
 
//Calculating Perimeter
double findPerimeter(double sideOne, double sideTwo)
{
    double perimeter = ((sideOne * 2) + (sideTwo * 2));
    return perimeter;
}
 
//Calculating diagnal
double findDiagonal(double sideOne, double sideTwo)
{
    double diagonalTotal = ((sideOne *sideOne) + (sideTwo*sideTwo));
    double diagonal = pow(diagonalTotal,0.5);
    return diagonal;
}
 
void display(double sideOne, double sideTwo, double area, double perimeter, double diagonal)
{
    cout << "The area is: " << area << endl << endl;
    cout << "The perimeter is: " << perimeter << endl<< endl;
    cout << "The diagonal is: " << diagonal << endl;
}

Hello to all,

I am cross compiling for an embedded development board and I have some strange issues with qt creator. qtbase was compiled successfully for the target board.

When I create a new project choosing the board that I want to build for, either a simple Console application or a QWidget application, from the first time that I configure the project, some issues appear in qt ‘Issues’ tab. Those issues concern the main types of like qt.

For console

0_1558371586873_20b97a24-50fc-481d-848c-c098dafb8134-image.png

main.cpp:7: error: unknown type name ‘QCoreApplication’

For QWidget

0_1558371651060_88b4daa5-2548-40a5-8b70-80b689d582c1-image.png

main.cpp:6: error: variable has incomplete type ‘QApplication’
qwindowdefs.h:81: forward declaration of ‘QApplication’
main.cpp:7: error: unknown type name ‘MainWindow’

The most strange thing is that the console program compiles and runs successfully remotely on the board, which gives me the indication that

Does anybody has any experience which any similar issue?

Thank you in advance
aplastiras

error: variable has incomplete type ‘void’

If you are getting this error message trying to compile code that used to work or from some example code you found somewhere it is very likely because of the changes in the XC8 interrupt syntax introduced with V2.0 of XC8.

Specifically I am getting this today for my interrupt service routine definition. I used to use the age-old way of doing this in XC8 as follows:

// Old way to do this

void interrupt  myISR(void) 
{
   // Old way Interrupt code here
}

After the changes to the XC8 compiler which were mostly motivated to get better C standard compliance, particularly with C99, the syntax for that function should now use the commonly adopted concept of function declaration-specifier attributes, which traditionally start with 2 underscores and contains either a list of parameters in brackets or have empty brackets if no parameters are present. 

// New and improved and C99 compliant way to specify an interrupt service routine in XC8

void __interrupt() myISR(void)
{
    // New and improved interrupt code here
}

This syntax is now also consistent between XC8, XC16 and XC32

Please see this post for more information on how to either work around this or change to the new syntax.

https://www.microforum.cc/topic/5-i-used-to-use-to-locate-variables-but-since-xc8-20-this-is-no-longer-working/

Возможно, вам также будет интересно:

  • V6 170410 kqcpet6 v6 таблица кодов и ошибок
  • Vanguard anti cheat valorant ошибка 128
  • Vandy vape jackaroo ошибка атомайзера
  • V0144 ошибка suzuki grand vitara
  • Van9003 valorant ошибка при запуске

  • Понравилась статья? Поделить с друзьями:
    0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии