VS Arduino
Visual Micro >> Project Guidance >> How to code cpp/h files that contain a class?
https://www.visualmicro.com/forums/YaBB.pl?num=1562272746

Message started by Abbott HMG on Jul 4th, 2019 at 8:39pm

Title: How to code cpp/h files that contain a class?
Post by Abbott HMG on Jul 4th, 2019 at 8:39pm
I've created cpp/h files in a test app (HMGHelloWorld). See attached zip.
When I compile it I get a redefinition of HMGHelloWorld error. I been trying for a while to work around this but to no avail. Any suggestions?

Abbott
https://www.visualmicro.com/forums/YaBB.pl?action=downloadfile;file=HMGHelloWorld.zip ( 261 KB | 1 Download )

Title: Re: How to code cpp/h files that contain a class?
Post by Visual Micro on Jul 4th, 2019 at 8:47pm
Hi,

This forum can only really cater for Visual Micro questions. You will find more experienced coders on stackoverflow and the arduino.cc forum.

One thing I could see in your code is that you redefine your class in the cpp. It is in both .h and .cpp

The cpp should define the class members a little like this.


Code (c++):
#include <Wire.h>
#include "HMGHelloWorld.h"

void HMGHelloWorld::Init()
{
     
}

VS Arduino » Powered by YaBB 2.6.12!
YaBB Forum Software © 2000-2024. All Rights Reserved.