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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:15:11+00:00 2026-05-27T14:15:11+00:00

I am new to C++ and troubling with strings in classes Date.cpp: #include stdafx.h

  • 0

I am new to C++ and troubling with strings in classes

Date.cpp:

#include "stdafx.h"
#include "Date.h"
#include <sstream>
#include <string>

using namespace std;

Date::Date(int day,int month,int year )
{
    setDate(day,month,year);
}

void Date::setDate(int day,int month,int year)
{
    this->day = day;
    this->month = month;
    this->year = year;
}

string Date::printIt()
{
    std::stringstream res;

    res<<this->day<<"/";
    res<<this->month<<"/";
    res<<this->year;

    return res.str;
}

Date operator+(const Date &date,int day)
{
    Date newDate(date.day,date.month,date.month);

    newDate.day += day;

    if(newDate.day > 30)
    {
        newDate.day%=30;
        newDate.month+=1;

        if(newDate.month>=12)
        {
            newDate.month%=30;
            newDate.year+=1;
        }
    }

    return newDate;
}

Date.h:

#ifndef DATE_H
#define DATE_H 

using namespace std;

class Date
{
private:
    int day,month,year;

    Date(){}

public:
    Date(int day,int month,int year);

    void setDate(int day,int month,int year);
    string printIt();

    friend Date operator+(const Date &date, int day);
};


#endif

The problem is printIt() function. Visual Studio says that declarations are incompatible. When I change the type of function to int the problem disappears but why there is a problem with strings?

  • 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-27T14:15:12+00:00Added an answer on May 27, 2026 at 2:15 pm

    Your problem is with your include order:

    #include "stdafx.h"
    #include "Date.h"
    #include <sstream>
    #include <string>
    

    You’re including Date.h, which contains string, before you include the header that defines string.

    It should be

    #include "stdafx.h"
    #include <sstream>
    #include <string>
    #include "Date.h"
    

    or better yet, include string directly in the header. This is so you don’t have to worry about the order in other cpp files where you might include the header.

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

Sidebar

Related Questions

New to javascript/jquery and having a hard time with using this or $(this) to
new Date(05-MAY-09 03.55.50) is any thing wrong with this ? i am getting illegalArgumentException
New day, new problem :-) Code: Client Side: void abw_Closed(object sender, EventArgs e) {
I am having troubling creating a nested signup form for users that are using
New to REgEX and in my sixties so bear with me Using ColdFusion so
New to mvc, I have a controller like this public ActionResult Index(DateTime Date, DateTime
New to Ruby and ROR and loving it each day, so here is my
New class is a subclass of the original object It needs to be php4
New to xml. Looking for XPath to search a xml file with python ElementTree
New to silverlight. Traditionally if I were to design a wizard-like process where a

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.