Parse issue when including JuceHeader in separate class header - Expected member name or ';' after declaration specifiers

#1

Hi,
I’m new to Juce and I’m currently trying to port a plugin I developed with the BlueCat Plug 'n script framework to Juce.
The main part of the code will go into the PluginProcessor but I have an extra class (Track) which is declared/defined in separate files.
This class must have access to the juce modules so I added
#include “…/JuceLibraryCode/JuceHeader.h”
to Track.hpp. The same include exists in the PluginProcessor.h.
The issue is that as soon as I include this to Track.hpp the compiler complains about a Parse issue:
…/JUCE/modules/juce_core/text/juce_Identifier.h:120:23: Expected member name or ‘;’ after declaration specifiers
…/JUCE/modules/juce_core/misc/juce_Uuid.h:59:17: Expected member name or ‘;’ after declaration specifiers
…/JUCE/modules/juce_core/containers/juce_Variant.h:285:46: Expected member name or ‘;’ after declaration specifiers
…/JUCE/modules/juce_graphics/images/juce_Image.h:420:48: Expected member name or ‘;’ after declaration specifiers

If I compile without the Track class everything goes well although PluginProcessor.h and PluginEditor.h both reference the very same files.

Below are the include directives in the different files:

Track.h:

#pragma once
#ifndef __TRACK_GUARD
#define __TRACK_GUARD
#include “Mofflr.h”
#endif
#include
#include
#include “…/JuceLibraryCode/JuceHeader.h”

Track.cpp:
#include “cpphelpers.h”
#include “Track.h”
#include <math.h>
#include

PluginProcessor.h:
#pragma once
#include “…/JuceLibraryCode/JuceHeader.h”
#include “Track.h”

PluginEditor.h:
#pragma once
#include “…/JuceLibraryCode/JuceHeader.h”
#include “PluginProcessor.h”

If someone could give me a hint as to what is going wrong here, it would be most appreciated.
Thank you

#2

My guess is that something in one of your headers that’s included before the juce header is doing #define null ...

1 Like
#3

@reuk
Thanks a lot for your reply.
Indeed the offending lines in the juce files are all somehow declarations of null.
I checked higher up in the headers referred to but as far is I can see it does not seem to be the case.

Below are the preprocessor statements in the header files I omitted previously.
I also searched in the std headers that I included (except std::thread, of which I can’t see the code).

MofflR.h:
#ifndef __MOFFLR_H_INCLUDED
#define __MOFFLR_H_INCLUDED
#include "cpphelpers.h"
#include <string>
#include <thread>
#include <vector>
...
#endif

cpphelpers.h:
/**
* C++ Helper classes and for angelscript compatibility.
* Copyright © 2015-2017 Blue Cat Audio. All rights reserved.
*/

#ifndef _cpphelpers_h
#define _cpphelpers_h

#include "dspapi.h"

#ifdef __cplusplus

// C++11 initializer lists compiler check
#ifdef _MSC_VER
#if _MSC_VER>=1800 // VS2013 required
#define CPP11_INITIALIZERS
#endif
#elif defined(__clang__)
#if __has_feature(cxx_generalized_initializers)
#define CPP11_INITIALIZERS
#endif
#elif defined(__GNUG__) &&  (__GNUC__ >= 4) && (__GNUC_MINOR__ >=4) // supported starting with GCC 4.4
#define CPP11_INITIALIZERS
#endif

#ifdef CPP11_INITIALIZERS
#include <initializer_list>
#endif

/** Simple array template class that can be used to define
 *  parameters, names and other script definition arrays with the same syntax as
 *  angelscript.
 *  This is not a smart array or vector implementation, just a simple helper template to build 
 *  your parameters list easily (C++11 recommended for full compatibility with angelscript syntax).
 */
template <typename T>
struct array
{
    // expected C-style struct data----------
    T*      ptr;
    uint    length;
    
    // Helper C++ constructors------------------
    
    /// constructor with size
    array(uint size=0);
    
    /// constructor with size and default valur for elements
    array(uint size,const T& defaultValue);
    
    /// constructor that takes a fixed size array
    /// can be used to construct the array from a fixed size C array
    template <int N>
    array(const T(&iArray)[N]);
    
#ifdef CPP11_INITIALIZERS
    /// C++11 iitializer list support
    array(const std::initializer_list<T>& list);
#endif

	array(const array<T>& iArray);
	array<T>& operator =(const array<T>& iArray);

    ///destructor
    ~array();
    
    // Helper C++ functions------------------
    
    /// array style accessor
    T& operator       [](uint i);
    
    /// array style accessor (const)
    const T& operator [](uint i)const;
    
    /// resize array (re-allocation and copy using the = operator)
    void resize(uint newSize);
    
    /// find element in array and returns its index or -1 if not found
    int find(const T& elem)const;
    
};

template <typename T>
array<T>::array(uint size):
ptr(null),
length(size)
{
    if (length != 0)
        ptr = new T[length];
}

template <typename T>
array<T>::array(uint size, const T& defaultValue):
ptr(null),
length(size)
{
    if (length != 0)
        ptr = new T[length];
    for(uint i=0;i<length;i++)
    {
        ptr[i]=defaultValue;
    }
}

template <typename T>
template <int N>
array<T>::array(const T(&iArray)[N]):
ptr(null),
length(N)
{
    if (length != 0)
        ptr = new T[length];
    for(uint i=0;i<N;i++)
    {
        ptr[i]=iArray[i];
    }
}

#ifdef CPP11_INITIALIZERS
template <typename T>
array<T>::array(const std::initializer_list<T>& list):
length(static_cast<uint>(list.size()))
{
	ptr = nullptr;
    if (length != 0)
    {
        ptr = new T[length];
        uint i = 0;
        for (typename std::initializer_list<T>::const_iterator iter = list.begin(); iter != list.end(); iter++)
        {
            ptr[i] = (*iter);
            i++;
        }
    }
}
#endif

template <typename T>
array<T>::array(const array<T>& iArray) :
	length(iArray.length)
{
	if (length != 0)
	{
		ptr = new T[length];
		for (uint i=0; i<length; ++i)
		{
			ptr[i] = iArray[i];
		}
	}
}

template <typename T>
array<T>& array<T>::operator =(const array<T>& iArray)
{
	// cleanup if different length
	if (iArray.length != length)
	{
		length = iArray.length;
		delete[] ptr;
		ptr = null;
	}
	if (length != 0)
	{
		if(ptr==null)
			ptr = new T[length];
		for (uint i = 0; i<length; ++i)
		{
			ptr[i] = iArray[i];
	//		i++;
		}
	}
	return *this;
}

template <typename T>
array<T>::~array()
{
    delete[] ptr;
    ptr = 0;
}

template <typename T>
T& array<T>::operator [](uint i)
{
    return ptr[i];
}

template <typename T>
const T& array<T>::operator [](uint i)const
{
    return ptr[i];
}

template <typename T>
void array<T>::resize(uint newSize)
{
    if(newSize!=length)
    {
        T* oldPtr=ptr;
        ptr=0;
        if(newSize>0)
        {
            ptr=new T[newSize];
            if(oldPtr!=0)
            {
                for(uint i=0;i<length;i++)
                {
                    ptr[i]=oldPtr[i];
                }
            }
        }
        delete [] oldPtr;
        length=newSize;
    }
}

template <typename T>
int array<T>::find(const T& elem)const
{
    int index=-1;
    for(uint i=0;i<length;i++)
    {
        if(ptr[i]==elem)
        {
            index=i;
            break;
        }
    }
    return index;
}

/** Array Descriptor class - basic array descriptor as required by host,
 *  without all the bells and whistles.
 */
template <typename T>
struct ArrayDescriptor
{
    // C-struct layout
    T*      ptr;
    uint    length;
    
    // utility constructor
    ArrayDescriptor():ptr(null),length(0){};
};

#endif
#endif

I will try excluding those headers one for one to find where null might have been defined.
Thanks

#4

I tracked down the culprit.
I found this line in one of the headers:

#define null 0

I removed the line and replaced it with the general macro NULL.

Now I got the project to compile.
Thanks a lot for your help.