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 1038065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:55:42+00:00 2026-05-16T14:55:42+00:00

I am getting an error when I declare a class: #include <iostream> #include testing/test.h

  • 0

I am getting an error when I declare a class:

#include <iostream>
#include "testing/test.h"
#include <string>
using namespace std;

int main(void)
{    
    test links;
    string content="this is an string";
    links.getcont(content);
}

test.h

#ifndef TEST_H_
#define TEST_H_
#include<string>
using namespace std;
class test {    
  public:    
    string getcont(string content); 

};

#endif /* TEST_H_ */

test.cpp

#include "test.h"
#include <iostream>
using namespace std;    
string getcont(string content)    
{
    cout << content;
    return content;
}

When I run this I get this error:

undefined reference to test::getcont(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)
  • 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-16T14:55:42+00:00Added an answer on May 16, 2026 at 2:55 pm

    Well , in your test.cpp file replace the getcont function for this

    string test::getcont(string content){ //code here; }
    

    The problem is that you are not saying that getcont is a member function of the test class.

    Also, consider making it a const function and passing a const string reference

    string
    test::getcont( const string& content) const
    {
        return content;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

include stdafx.h #include <iostream> using namespace std; class Foo{ public: void func() { cout<<Hello!!<<endl;
id.cpp #include stdafx.h #include <iostream> using namespace std; class A { public: static int
I have written the following code: #include <iostream> using namespace std; template <class T>
I'm getting this error whenever I attempt to declare a class: Parse error: syntax
I am getting an error when using .Include - A specified Include path is
I'm getting an error msg DataReader.h:13: error: 'String' was not declared in this scope
I'm getting error while using replace in an update statement in sql server 2008.
I am using forward declaration and now I am getting an error referring to
I'm getting the following compile error in one of my classes, using gcc 3.4.5
Hey i'm getting this odd error when I leave the namespace sf{ declaration in

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.