samedi 17 novembre 2018

C++ setters and getters for string

I have no idea what is wrong. Probably some typo, but can't figure out:

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

class Test {
private:
    std::string Artist;
public:
    Test();
    ~Test();

    void setArtist(string i);
    string getArtist();
};

cpp:

#include "Test.h"
#include<cstdlib>
#include <string>
#include<iostream>
using namespace std;

void Test::setArtist(string i) {
    Artist = i;
};

string Test::getArtist() {
    return Artist;
}

Test::Test()
{
}

Test::~Test()
{
}

main:

#include "Test.h"
using namespace std;

int main() {

    system("pause");
    return 0;
}

errors are those:

Error C2061 syntax error: identifier 'string' Test
Error C3646 'getArtist': unknown override specifier Test
Error C2059 syntax error: '(' Test Error C2238 unexpected token(s) preceding ';' Test Error C2061 syntax error: identifier 'string' Test

I'm using VisualStudio 2017

Aucun commentaire:

Enregistrer un commentaire