c++ - Trying to define a function, but I get "variable or field `function_A' declared void" -
#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; class student; void function_a(student& s) class student { void function_b() { ::function_a(*this); } int courses; }; void function_a(student& s) { // line 18 (where error occurring) s.courses = 1; } int main() { student s; s.function_b(); return 0; }
the error getting follows:
(line 18) new types may not defined in return type.
part of problem you're using type student
before it's defined making parameter function_a
. make work need
- add forward declaration
function_a
- switch
function_a
take pointer or reference - move
function_a
afterstudent
. necessary membercourses
defined before it's accessed - add
;
after end ofclass student
definition
try following
class student; void function_a(student& s); class student { // of student code }; void function_a(student& s) { s.courses = 1; }
Comments
Post a Comment