new to c++ errors with .ccp and .h files

this is my .cpp file

#include <iostream>
#include <string>
#include <cstring>
#include <stdio.h>


#ifdef WINDOWS
#include <Windows.h>
#endif
//#ifdef LINUX
#include <unistd.h>
//#endif

using namespace std;

struct OnOff
{
const char *LOW;
const char *HIGH;
};

const OnOff onoff = {"0","1"};


const char *getLEDhandle(std::string USRled){
std::string fpath = "/sys/class/leds/beaglebone:green:";
std::string LEDusr = "/brightness";
std::string filepath;
filepath += fpath + USRled + LEDusr;
//cout << filepath <<endl;
const char *LEDBrightness = filepath.c_str();
return LEDBrightness;
}

this is the .h file

#ifndef GPIOlib_H
#define GPIOlib_H
#define LINUX
#include "GPIOlib1.cpp"

const char *getLEDhandle(std::string);

#endif

if I compile using Dev c++ under windows it compiles fine

but under Linux with eclipse c++
I get the error that
const char *getLEDhandle(std::string); has already been defined.

any suggestions?

thanks gary
Hi,

Don't include cpp files :+) Instead, include the header file in the cpp file.
Thanks I ended up figuring that out but ran into another problem seem lit its the h file ,

const char *getLEDhandle(std::string, string[]);

am I not allowed to use string[] from here I keep getting a string error
from here, is so what it the best way to go?.

Thanks gary
Did you try to properly scope the std::namespace everywhere?

Something like: std::string getLEDhandle(std::string, std::string[]);

Last edited on
I did get it to work I already had, using namespace std, but added using std::string;

That seemed to work

thanks gary
I did get it to work I already had, using namespace std,


Just some advice, avoid doing that - it's best to put std:: before every std thing. It will help you avoid your current problem and other naming conflicts. Read up about what namespaces are and why we use them.
Also:

Provide variable names for the parameters in function declarations, make them the same as the function definition.

Pass std::string by reference. Same for any class or type that is not built-in.

Consider making the parameters const wherever you can. In fact use const wherever you can - this is called const correctness.
Topic archived. No new replies allowed.