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

  1. add forward declaration function_a
  2. switch function_a take pointer or reference
  3. move function_a after student. necessary member courses defined before it's accessed
  4. add ; after end of class 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

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -