Jan 9, 2017 at 11:37pm UTC
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
Jan 10, 2017 at 2:08am UTC
Hi,
Don't include cpp files :+) Instead, include the header file in the cpp file.
Jan 10, 2017 at 6:34pm UTC
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
Jan 10, 2017 at 9:03pm UTC
Did you try to properly scope the std::namespace everywhere?
Something like: std::string getLEDhandle(std::string, std::string[]);
Last edited on Jan 10, 2017 at 9:03pm UTC
Jan 11, 2017 at 12:56am UTC
I did get it to work I already had, using namespace std, but added using std::string;
That seemed to work
thanks gary
Jan 11, 2017 at 1:10am UTC
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.