Compile error: 'CS0_PIN' is not a type

Hi,

I am trying to use a library from Playing with Fusion to read temperature data from a MAX31865 chip. When I use the library in the .ino file it works, but when I try to encapsulate the access into a separate class, I get a compiler error that I do not understand. I am using Atmel studio 6.2 with the Visual Micro plugin, but the same compiler error occurs when I use the Arduino IDE. Here are the relevant parts of code.

The library defines in it's header file a constructor that accepts a pin number for the chip select line:

class PWFusion_MAX31865_RTD
{
 public:
  // constructor
  PWFusion_MAX31865_RTD(int8_t CSx);
  
  // skipping the rest
};

I made a new class, and this is the header file:

// need to use absolute path otherwise the library is not found
// somehow the path is not set correct, but this is a different problem
#include "C:/.../PlayingWithFusion_MAX31865.h"
#include "C:/...PlayingWithFusion_MAX31865_STRUCT.h"

// skipping some more includes

class TemperatureClass
{
 protected:
	const int8_t CS0_PIN = 9;
	
	// this causes a compile error: 'CS0_PIN' is not a type
	PWFusion_MAX31865_RTD rtd_ch0(CS0_PIN);
	
	// skipping the rest
};

// this was suggested by the Visual Micro template, not sure
// why this construct is used
extern TemperatureClass Temperature;

Why is the compiler expecting a type? Am I not instantiating a variable rtd_ch0 by calling the constructor of class PWFusion_MAX31865_RTD in the line that causes the compile error?

I need to access variable rtd_ch0 from multiple methods, so it should be a member variable of the Temperature class. I could probably declare a pointer to class PWFusion_MAX31865_RTD and instantiate an object in the constructor of Temperature class, but I would still like to understand what I am doing wrong, as it would be the more elegant solution.

Thanks,
Kurt

	// this causes a compile error: 'CS0_PIN' is not a type
	PWFusion_MAX31865_RTD rtd_ch0(CS0_PIN);

You are defining, not calling, a function. In the definition of a function, the type(s) of the argument(s) MUST be stated.

So what would the correct syntax be to instantiate an object of class PWFusion_MAX31865_RTD in the header of the Temperature class?

So what would the correct syntax be to instantiate an object of class PWFusion_MAX31865_RTD in the header of the Temperature class?

There isn't any. Objects are DECLARED in the header file. They are defined/instantiated in the source file.

Thanks. Good to know that in C++ one has to use pointers for member variables to other classes.

The answer that C++ does not allow one to instantiate other classes as member variables without using a pointer to the other class' object was not satisfying. So I kept asking, and the answer to the problem seems to be Constructors and member initializer lists.

I haven't tried it in my solution because I use a different approach altogether, but thought I post (kind of) an answer in case anybody else stumbles over this post.

Best,
Kurt