when i,

g++ -c Serdar.cc

compiler says:

Serdar.cc:3: error: semicolon missing after declaration of `Serdar'
Serdar.cc:4: error: ISO C++ forbids defining types within return type
Serdar.cc:4: error: two or more data types in declaration of `SetValue'
Serdar.cc:4: error: prototype for `Serdar Serdar::SetValue(const int&)' does 
   not match any in class `Serdar'
Serdar.hh:5: error: candidate is: void Serdar::SetValue(const int&)
Serdar.cc:4: error: `Serdar Serdar::SetValue(const int&)' and `void 
   Serdar::SetValue(const int&)' cannot be overloaded
Serdar.cc:4: error: semicolon missing after declaration of `class Serdar'
Serdar.cc: In member function `int& Serdar::GetValue()':
Serdar.cc:10: error: request for member `deger' in `this', which is of 
   non-class type `Serdar* const'

file:

class Serdar
{
        public:
                void SetValue(const int &a);
                int & GetValue();
        private:
                int deger;
}

file:

#include "Serdar.hh"
void Serdar::SetValue(const int &a)
{
        deger = a;
}
int & Serdar::GetValue()
{
        return & this.deger;
}

Dani AI

Generated

Most of the error messages are cascading: the compiler got confused early and then produced a bunch of followups. As hinted, the immediate problem is the missing semicolon after the class definition in the header. That parse error makes later tokens look like malformed types or declarations, which explains the “ISO C++ forbids defining types within return type” and the other mismatch/overload complaints.

Fixes to apply (minimal, focused):

  • Terminate the class declaration with a trailing semicolon and add include guards.
  • In the getter implementation, this is a pointer (use this->member if using this), and return &this->deger; returns an int* whereas the function expects int&. Return the member itself (or this->deger) to satisfy the int& return type.

Example of corrected layout:

#ifndef SERDAR_HH
#define SERDAR_HH

class Serdar {
public:
    void SetValue(int a);
    int& GetValue();
private:
    int deger;
};

#endif
#include "Serdar.hh"

void Serdar::SetValue(int a) { deger = a; }
int& Serdar::GetValue()      { return deger; }  // or "return this->deger;"

Extra notes: for primitive types prefer passing by value (int a) instead of const int& (no cost advantage for int). Consider making the getter int GetValue() const (return by value) or const int& GetValue() const if exposing a read-only reference. After applying the semicolon and fixing the getter, recompile; most of the displayed errors should disappear. This should resolve the issues reported by .

Member Avatar for Member #46692

Don't class declarations need a semicolon after 'em?

int & Serdar::GetValue()
That looks odd. Might be ok ain't checked it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.