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

  • SEARCH
  • Home
  • 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 4242624
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:28:04+00:00 2026-05-21T03:28:04+00:00

I encounter a problem using std::string in parameters : MyClass has a method like

  • 0

I encounter a problem using std::string in parameters :

MyClass has a method like this

public:  
    void loadDatas(string filename);

In my main.cpp I have the following simple code :

#include <iostream>
#include <string>

#include "myclass.hpp";

using namespace std;

int main()
{

    string foo = "test.txt";
    cout << foo << endl; // Print Hello Kitty, no problems

    MyClass i;
    // The following line raise :
    // obj/Release/src/main.o||In function `main':|
    // main.cpp|| undefined reference to `MyClass::loadDatas(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'|
    // ||=== Build finished: 1 errors, 0 warnings ===|
    i.loadDatas(foo);

    return EXIT_SUCCESS;

}

So it looks like libstdc++ is well linked (because I’m able to print the text using cout), but passing a string in parameters raise an error and I don’t understand why.

Could someone help me please ?

EDIT : I made a mistake, in fact it is i.loadDatas(foo); (I corrected it). My source code isn’t in english so I tryed to made a simple version for you in english. I really call an instance method and not a static method.

EDIT 2 : Complete source code

personnage.hpp

#ifndef PERSONNAGE_H
#define PERSONNAGE_H

#include <iostream>
#include <string>

#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/xmlmemory.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>

#include "carte.hpp"

using namespace std;

class Personnage : public Carte
{

    public:

        Personnage();

        void chargerPersonnage(string nom);

        virtual ~Personnage();

    private:

        //! Le texte d'accroche de la carte
        string _accroche;

};

#endif // PERSONNAGE_H

personnage.cpp

#include "personnage.hpp"

Personnage::Personnage() : Carte("Sans titre")
{

}

void chargerPersonnage(string nom)
{

}

Personnage::~Personnage()
{
    //dtor
}

main.cpp

#include <iostream>
#include <string>

#include <SFML/Graphics.hpp>

#include "personnage.hpp"

using namespace sf;
using namespace std;

int main()
{

    string test = "Hello Kitty";
    cout << test << endl;

    Personnage test2;
    test2.chargerPersonnage(test);

    return EXIT_SUCCESS;
}

error log

obj/Release/src/main.o||In function `main':|
main.cpp|| undefined reference to `Personnage::chargerPersonnage(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'|
||=== Build finished: 1 errors, 0 warnings ===|
  • 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-05-21T03:28:04+00:00Added an answer on May 21, 2026 at 3:28 am

    The problem is that you’ve defined class Personnage as having a member function chargerPersonnage, but in personnage.cpp you define a free function chargerPersonnage instead.

    You appear to know the correct syntax, as you did Personnage‘s constructor and destructor correctly, but just to make it clear: Change void chargerPersonnage(string nom) { } to void Personnage::chargerPersonnage(string nom) { } in personnage.cpp.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Uhm I'm not sure if anyone has encountered this problem a brief description is
We encountered a problem with using Subversion on Windows. A developer committed a file
I am using ajaxForm. Now I have encountered a problem. My idea is when
I encountered a problem when running some old code that was handed down to
I recently encountered a problem where a value was null if accessed with Request.Form
I've encountered a problem when retrieving a JSONP response from a server in a
I've encountered a problem with my Netbeans 6.1 IDE. After an unsuccessful update, Netbeans
I have encountered a problem that I have not come accross yet when setting
I'm migrating a TSQL stored procedure to PL/SQL and have encountered a problem -
I encountered a strange problem today. Whenever i put a breakpoint in one of

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.