returning a pointer getting an error: 'swedish' was not declared in this scope

Hey everyone !
I'm getting en error : 'swedish' was not declared in this scope. Same goes for get_eng() method too sure.
Been searching so much no result... hope you can help guys^^.

this is my code:

Word.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef WORD_H
#define WORD_H

using namespace std;

class Word {
    public:
        char *swedish;
        char *english;
        Word(char *sw, char *eng); //Svenskt sw, engelskt eng
        ~Word();
        const char *get_sw() const; //Hämta svenskt ord
        const char *get_eng() const; //Hämta engelsk översättning

    private:

};

#endif 


Word.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "Word.h"
#include <iostream>
#include <vector>
#include <ctime>
#include <stdio.h>

#include <stdlib.h>


Word::Word(char *sw, char *eng){
    *swedish = *sw;
    *english = *eng;
}
char* Word::*get_sw(){
    return swedish;
}

const char* Word::*get_eng(){
    return english;
}
Word::~Word(){
    delete swedish;
    delete english;
}



regards
Nilo
Last edited on
Get rid of the asterisk before the function name and make sure the const is consistent with how you declared the function in the class definition.
I tried to add the const but it doesnt work... how should i write it to the function definition?
1
2
3
const char* Word:: get_sw() const {
//                ^
//                No asterisk here! 
Last edited on
oh yes, it worked now ! Many thanks :)
Topic archived. No new replies allowed.