# C++ A class constructor (solved)

**URL:** <https://community.particle.io/t/c-a-class-constructor-solved/47621>\
**Category:** Firmware\
**Created:** [February 7, 2019, 5:25pm UTC](https://community.particle.io/t/c-a-class-constructor-solved/47621 "2019-02-07T17:25:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tentoes](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/tentoes/32/20045_2.png) [@Tentoes](https://community.particle.io/u/Tentoes)\
**Post date:** [February 7, 2019, 5:25pm UTC](https://community.particle.io/t/c-a-class-constructor-solved/47621/1 "2019-02-07T17:25:30Z")

</div>

Trying something new, so naturally, I am confused.

I have a “screen” class:

```auto
class Screen
{
public:
	virtual void Switch() ;
	virtual int Loop(unsigned long ms)=0;
};

```

The idea is to have a variable pointing to an object of this class so I can switch from one object to another by changing this variable.

So one of the “screens” is the “TemperatureScreen”

```auto
class TempScreen: public Screen
{
	int TempCol = 0 ;
	unsigned long nextMeatTime = 0 ;
	unsigned long nextChamberTime = 0 ;
	unsigned int BkColor ;
	void ShowTemp( int Pin, int y);

public:
	TempScreen() ;
	virtual void Switch() ;
	virtual int Loop(unsigned long ms);
};

```

You see this is a screen with some members, including the required Switch and Loop.

So the constructor in .cpp file is simple:

```auto
TempScreen::TempScreen()
{
	BkColor = tftBLUEVIOLET ;
}

```

But the compiler always complains that TempScreen::TempScreen does not name a type. As far as I can tell, it isn’t supposed to, but you just can’t win an argument with a compiler.

---

<div class="post-metadata">

**Author:** ![Tentoes](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/tentoes/32/20045_2.png) [@Tentoes](https://community.particle.io/u/Tentoes)\
**Post date:** [February 7, 2019, 5:33pm UTC](https://community.particle.io/t/c-a-class-constructor-solved/47621/2 "2019-02-07T17:33:21Z")

</div>

Compiler doesn’t seem to understand that the cpp file contains the methods mentioned in the .h file. I got rid of the constructor, but the methods fail.

Maybe my .h files need to be .hpp files?

---

<div class="post-metadata">

**Author:** ![Tentoes](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/tentoes/32/20045_2.png) [@Tentoes](https://community.particle.io/u/Tentoes)\
**Post date:** [February 7, 2019, 5:51pm UTC](https://community.particle.io/t/c-a-class-constructor-solved/47621/3 "2019-02-07T17:51:01Z")

</div>

Forgot to include the .h file in the .cpp file

---

<div class="post-metadata">

**Author:** ![KyleG](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/kyleg/32/11077_2.png) [@KyleG](https://community.particle.io/u/KyleG)\
**Post date:** [February 9, 2019, 1:48am UTC](https://community.particle.io/t/c-a-class-constructor-solved/47621/4 "2019-02-09T01:48:33Z")

</div>

Thank you for putting your solution!

---

<div class="post-metadata">

**Author:** ![KyleG](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/kyleg/32/11077_2.png) [@KyleG](https://community.particle.io/u/KyleG)\
**Post date:** [February 9, 2019, 1:48am UTC](https://community.particle.io/t/c-a-class-constructor-solved/47621/5 "2019-02-09T01:48:41Z")

</div>


