1

main.cpp

#include "personel.h"
#include "functions.h"
#include <iostream>
#include <string>
#include <vector>


int main()
{
    while (true)
    {
        std::cout << "welcome.\n 1 to register, 2 to login\n";
        //register or login
        int rORl = 0;
        std::cin >> rORl;
        if (rORl == 1)
        {
            register();
        }
        else if (rORl == 2)
        {
            std::cout << "logged in";
        }

    };
}

functions.h

#pragma once

#include <iostream>

void register();

functions.cpp

#include "functions.h"

void register()
{
    std::cout << "hi\n";
};



personel.h

#pragma once
#include <iostream>
#include <string>
#include <vector>

struct Post
{
    std::string content;
    std::string timestamp;
};

struct FollowerNode
{
    int userID;
    FollowerNode* next;
};

class personel
{
    std::string password;
    std::string username;
    std::string name;
    std::vector<int> followers;
    std::vector<Post> posts;
 };



Im getting "a global-scope declaration may not have this storage class" on the register function. obviously the code isnt finished yet. But I'm expecting it to output hi when 1 is pressed but it doesnt even compile

many google searches. all ive found is "i left it alone for a few hours and it went away by itself"

Thumper
  • 21
  • 2

1 Answers1

1

In C++, until C++20, register was a keyword that meant an object should be stored in a CPU register if possible. It defined a storage class like static or extern. It looked like register int i = 0;.

Since C++20 register is an unused but reserved keyword in C++.

See register.

Keywords are reserved identifiers : "identifiers that are keywords cannot be used for other purposes;" That means you can't use register as the name of a function, even if it isn't used by the language anymore because it's still a keyword.

Your function declaration is similar to void static();. Changing the name of your function to an allowed identifier should solve your problem.

François Andrieux
  • 28,148
  • 6
  • 56
  • 87