-2

Relearning C/C++ after 3 years of JavaScript (I've gotten way too comfortable..)

I'm building a test file with input. The problem is within cTool, where the first function is not letting me return a string. I thought this was totally valid if the library is included in the header file? What am I overlooking here.

cTool.cpp

string getInfo(void) {
}

void parseInfo(void (*getInfo)()) {
}

float assessInfo(float number) {
}

...

cTool.h

#pragma once
#ifndef ASSESS_GRADE_H
#define ASSESS_GRADE_H

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

using namespace std;

string getInfo(void);
void parseInfo(void(*getInputFunc)());
float assessInfo(float number);
float assessInfo(char letter);
float assessInfo(int *array);

#endif

cMain.cpp

#include "cTool.h";

int main (void) {
    // function call from cTool.cpp
    return 0;
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Robolisk
  • 1,682
  • 5
  • 22
  • 49

1 Answers1

2

You need to add #include "cTool.h" to cTool.cpp, not just to cMain.cpp only. Otherwise, when compiling cTool.cpp, the compiler doesn't know what a string is since it doesn't see your #include <string> and using namespace std; statements (BTW, using namespace std; in a header file is a very bad idea).

cTool.cpp

#include "cTool.h" // <-- ADD THIS!

std::string getInfo(void) {
}

void parseInfo(void (*getInfo)()) {
}

float assessInfo(float number) {
}

...

cTool.h

#pragma once
#ifndef ASSESS_GRADE_H
#define ASSESS_GRADE_H

#include <string>
#include <iostream>

std::string getInfo(void);
void parseInfo(void(*getInputFunc)());
float assessInfo(float number);
float assessInfo(char letter);
float assessInfo(int *array);

#endif

cMain.cpp

#include "cTool.h";

int main (void) {
    // function call from cTool.cpp
    return 0;
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770