Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8457013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:41:51+00:00 2026-06-10T12:41:51+00:00

I started learning C++, classes, objects, structures and more, but I’m having some problems

  • 0

I started learning C++, classes, objects, structures and more, but I’m having some problems with this.

#include <iostream>

using namespace std;

class Owner
{
    public:
        // Getters
        string GetName(){return info.name;}
        int GetAge(){return info.age;}
        short int GetGender(){return info.gender;}

        // Setters
        void SetName(string value){info.name = value;}
        void SetAge(int value){info.age = value;}
        void SetGender(short int value){info.gender = value;}
    private:
        struct info
        {
            string name;
            int age;
            short int gender;
        };
};

class Pet
{
    public:
        // Getters
        string GetName(){return info.name;}
        int GetAge(){return info.age;}
        short int GetGender(){return info.gender;}

        // Setters
        void SetName(string value){info.name = value;}
        void SetAge(int value){info.age = value;}
        void SetGender(short int value){info.gender = value;}
    private:
        struct info
        {
            string name;
            int age;
            short int gender;
        }
};


int main()
{

    // Creating object ...

    cout << "qq" << endl;



    return 0;
}

But I get these errors when I try to compile it:

In member function 'std::string Owner::GetName()':|
main.cpp|9|error: expected primary-expression before '.' token|
In member function 'int Owner::GetAge()':|
main.cpp|10|error: expected primary-expression before '.' token|
In member function 'short int Owner::GetGender()':|
main.cpp|11|error: expected primary-expression before '.' token|
In member function 'void Owner::SetName(std::string)':|
main.cpp|14|error: expected unqualified-id before '.' token|
In member function 'void Owner::SetAge(int)':|
main.cpp|15|error: expected unqualified-id before '.' token|
In member function 'void Owner::SetGender(short int)':|
main.cpp|16|error: expected unqualified-id before '.' token|
main.cpp|45|error: expected unqualified-id before '}' token|
In member function 'std::string Pet::GetName()':|
main.cpp|30|error: expected primary-expression before '.' token|
In member function 'int Pet::GetAge()':|
main.cpp|31|error: expected primary-expression before '.' token|
In member function 'short int Pet::GetGender()':|
main.cpp|32|error: expected primary-expression before '.' token|
In member function 'void Pet::SetName(std::string)':|
main.cpp|35|error: expected unqualified-id before '.' token|
In member function 'void Pet::SetAge(int)':|
main.cpp|36|error: expected unqualified-id before '.' token|
In member function 'void Pet::SetGender(short int)':|
main.cpp|37|error: expected unqualified-id before '.' token|
||=== Build finished: 13 errors, 0 warnings ===|

Why does it give me so many errors?

I don’t know why, because it is obvious that, for example,

 string GetName()
 {
     return info.name;
 }

returns a string, from the structure info.name

I’m using CodeBlocks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:41:53+00:00Added an answer on June 10, 2026 at 12:41 pm

    You’re misunderstanding the syntax of the struct keyword, furthermore the actual member variable has to be declared before the member functions accessing it. So change your class declarations to something like

    class Owner
    {
    private:
        struct
        {
            string name;
            int age;
            short int gender;
        } info;
    
    public:
        // Getters
        string GetName(){return info.name;}
        int GetAge(){return info.age;}
        short int GetGender(){return info.gender;}
    
        // Setters
        void SetName(string value){info.name = value;}
        void SetAge(int value){info.age = value;}
        void SetGender(short int value){info.gender = value;}
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just started learning PySide and is having problem with QTimer I have this #!/usr/bin/python
I just started learning objective c. I have this little problems and questions, hope
I just started learning classes in C++ and I get this error for the
I have just started using sass and still learning. I am using this command
I've just started learning ruby, so this question is simple. I created @subject in
First of all, this is my code (just started learning java): Queue<String> qe =
I started learning LISP and I heard that there is some kind of a
I started learning vim today and installed it using sudo apt-get install vim Now,
I have created some C++ classes to model a Solitaire game as a learning
I've done my C++ classes and practices after which I started learning Visual C++

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.