VS 2012 (Visual C ): error C2143: syntax error: miss ";" before "*" [closed]

StackOverflow https://stackoverflow.com/questions/14618691

  •  06-03-2022
  •  | 
  •  

Вопрос

I have this error at "iterator_of_array_int.h":

#include "array_of_int.h"
#include <cstdlib>    
namespace leonidandand {
    class iterator_of_array_int
    {           
    private:
        std::size_t index;
        // next line has error
        array_of_int * ptr_to_arr;
        friend class array_of_int;
    };
}

"array_of_int.h"

#pragma once

#include <cstdlib>
#include "iterator_of_array_int.h"
namespace leonidandand {
    class array_of_int {
    public:    
        typedef iterator_of_array_int iterator;
        iterator_of_array_int begin();
        iterator_of_array_int end();
    };
}

I included "array_of_int.h". What's wrong???

Это было полезно?

Решение

You included array_of_int.h which, before defining array_of_int, included iterator_of_array_int.h. So when the compiler sees your error line, it hasn't seen any declaration of the name array_of_int. The error message isn't one of the more helpful ones issued by a compiler.

I'm in the habit of forward-declaring classes in headers; that's all you need in iterator_of_array_int.h, so replace the include line with class array_of_int; and that one's good.

Другие советы

Normally that error means it doesnt recognise the type you put before the ' * '

Assuming you have your array_of_int struct / class definition on array_of_int.h, check you have semicolon at the end of the definition. It seems that type is not properly recognized by the compiler

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top