Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
How do you call a function from a source file from a header file?
//h.h
extern string pic;
class takePic
{
public:
void warPic();
void artPic();
void fatePic();
void painPic();
void noPic();
};
// second part of the same header where it calls the function
takePic picture;
void pictureType()
{
if (pic == "war")
{
picture.warPic();
}
else if (pic == "fate")
{
picture.fatePic();
}
else if (pic == "pain")
{
picture.painPic();
}
else if (pic == "art")
{
picture.artPic();
}
else
{
picture.noPic();
}
}
When I do this it says that the linker is not working.
This is the error linker command failed with exit code 1.
What happens if you change
void pictureType()
to
inline void pictureType()
You should really tell us the whole error message, and perhaps try searching for that before asking a question.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
myFunction(){
char *tempPath = getenv("LocalAppData");
strcat(tempPath, "\\MS\\namedPipe.json");
printf(" the path is %s \n",tempPath
}
int main(){
myFunction();
myFunction();
return 0;
}
I don't know the second time that I call this function I am getting the path to be appended like
Quoting the man page for getenv:
As typically implemented, getenv() returns a pointer to a string within the environment list. The caller must take care not to modify this string, since that would change the environment of the process.
In other words, what you are currently doing is not allowed.
Instead make another buffer and concatenate in that buffer. Eg:
char *tempPath = getenv("LocalAppData");
if (tempPath != NULL)
{
std::string env;
env = tempPath;
env += "\\MS\\namedPipe.json"
std::cout << env;
}
else
{
std::cout << "No such environment variable\n";
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
template<class Type>
void linkedQueueType<Type>::mergeSort() {
mergeSort(queueFront);
if (queueFront == NULL)
queueRear = NULL;
else {
queueRear = queueFront;
while (queueRear->link != NULL)
queueRear = queueRear->link;
}
return;
}
I am not understanding this merging sort.
It looks like this function is the main mergeStort entry point. It calls a helper function (also called mergeSort) to do the actual sorting. But it looks like the helper function doesn't set queueRear correctly, so after calling the helper function, this function has to set queueRear to point to the last entry in the queue (or NULL if the queue is empty).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
First of all, I'm gonna say thank you to who help me
so recently I was working on a project which is called Green House in Arduino
then I was about to write a function that reads sensor, and a function that prints that value in function1 and I just came up with some problems,
Here is My code
First of all, I just defined every pin and then
written functions
and this is functions and the main code which has problems
void GetState();
void loop() {
// put your main code here, to run repeatedly:
GetState();
PrintState();
delay(2000);
}
void PrintState()
{
Serial.println("TEMP ");
Serial.println(temp);
Serial.println("Rotobate Khak");
Serial.println(soilstate);
Serial.println("Humidity");
Serial.println(hum);
Serial.println("LDR === ");
Serial.println(LDRSTATE);
Serial.print("\n");
}
void GetState()
{
DHT.read11(Sensor);
int LDRSTATE=analogRead(LDR);
return LDRSTATE;
int soilstate=analogRead(soil);
soilstate= map(soilstate,0,1023,100.00,0);
return soilstate;
int temp=DHT.temperature;
return temp;
int hum=DHT.humidity;
return hum;
}
and I get 'temp' was not declared in this scope error
Declare "int temp;" at the top. The same for all other variables. Do not declare the variables in GetState, just use them.
Remove all "return" lines from Getstate(). Just setting "temp=DHT.temperature;" sets the variable and is enough.
Put the GetState() function before loop() (where it is called). Or, if you prefer, you can add a prototype before loop():
void GetState();
void loop() {
...
Think you are quite new to programming. Please try giving prototypes of GetState() and PrintState() functions above their definition. This is because C/C++ compiler assumes that it returns int by default if there isn't any prototype.
Otherwise, you can create a header file and then include that header file in this program.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a XML-file holding among other things some groups with name and userlists. In my code in constructor I have set a dictionary for this list:
dictGroups= QMap<QString, QList<QString>>() ;
In headerfile it is declared as
public:
QMap<QString, QList<QString>> dictGroups;
Then I read the file: ReadConfig();
void AppConfig::ReadConfig(void)
{
...
while(!reader.atEnd())
{
ReadGroups(reader);
if (dictGroups.isEmpty()) qDebug()<<"ReadConfig_isEmpty";
}
...
This is my ReadGroups:
void AppConfig::ReadGroups(QXmlStreamReader &reader)
{
dictGroups.clear();
while(!reader.atEnd())
{
reader.readNext();
if (reader.error())
{
...
}
else
{
if (reader.isStartElement())
{
if (reader.name().toString().toLower()=="group"){
ReadGroup(reader);
if (dictGroups.isEmpty()) qDebug()<<"ReadGroups_isEmpty";
}
}
else if (reader.isEndElement())
{
if (reader.name().toString().toLower() == "groups")
{
if(dictGroups.count()<=0){
QList<QString> users= QList<QString>();
users.append(this->GetUsername());
dictGroups.insert("admin", users);
}
return;
}
}
}
}
}
My problem is, that the items inserted in dictGroups while ReadGroups get lost. I get the debug output
ReadConfig_isEmpty
but in ReadGroups seems everything is ok.
I'm at a loss, puzzling around for hours, can anybody help to find the reason?
You have this code:
dictGroups.clear();
Why do you expect the dictGroups to persist when you clear them on every iteration of the outer loop? Don't do that.
The clear statement belongs perhaps at the beginning of ReadConfig.
Your method name capitalizations are very much out of place in Qt code, though: capitalized names are by convention reserved for groups.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am working on an object-oriented C++ coursework where I need to return error codes from the main function. How would one do this properly?
Unfortunately this is an assessed coursework so I cannot post my code here. But let's say the case is as follows:
I'm building an enigma machine with classes Plugboard, Reflector, and Rotor. I pass each of the configuration files as arguments in the command line. In this task, I'm provided with a file errors.h containing the following:
#define INSUFFICIENT_NUMBER_OF_PARAMETERS 1
#define INVALID_INPUT_CHARACTER 2
#define INVALID_INDEX 3
// and so on...
So I have in my program several functions to check the errors, for example a function to check whether the configuration file contains an invalid character (it has to be 0 to 25). I was thinking of setting this as a boolean function and then in my main function have the following:
if (!plugboard.check_invalid_character(/*some arguments*/)) {
cerr << "Invalid character!" << endl;
return 2;
}
But I'm not completely sure this is the right way to do it? Is it too superficial? Is there a more elegant way of returning error?
I hope my question is a little clearer this time. Thanks before.
You just need to return the value 4 in your main method like this:
int main() {
return 4;
}
Please note that your main function could also have the arguments vector and the argument count so there could be more in the brackets.
If KLibby is right and you use a method with returns the value you need to use something like that:
int doSomething() {
return 4;
}
int main() {
return doSomething();
}