I'm programing my first app with Visual Studio and I don't understand an Error that it shows me.
There're two files, Session and Login. Login uses the set and get functions of Session. As you can see bellow, Login calls "setCurrentLang" and this is the message Visual Studio shows: "this declaration has no storage class or type specifier" on Login.cpp. if I compile, this is the error then:
"Error 26 error C2365: 'setCurrentLang' : redefinition; previous definition was 'function' (....)\GUI\Login.cpp".
This is the Session.cpp file:
#include "Session.h"
const char* CURRENT_LANG;
void setCurrentLang( char* lang){
CURRENT_LANG = strdup(lang);
}
const char* getCurrentLang(){
return CURRENT_LANG;
}
Session.h
#ifndef __SESSION_H__
#define __SESSION_H__
#include <cstring>
#include <stdio.h>
void setCurrentLang( char* lang);
const char* getCurrentLang();
#endif
Login.cpp
#include "Login.h"
#include "../data/Session.h"
setCurrentLang("English");
Thank you very much for your help!
You call the method outside of any context. This is not possible. If you want to set the language on start, you can either call it at the beginning of main or use a dummy static class that calls it in its constructor:
static class LanguageSetter
{
public:
LanguageSetter()
{
setCurrentLang("English");
}
} dummy;
Or simply set the default value in the definition of CURRENT_LANG:
// std::string because this is C++, not C
std::string CURRENT_LANG = "English";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With