// ConsoleApplication7.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include<string>
#include<vector>
#include<functional>
using namespace std;
using namespace placeholders;
class TextQuery
{
public:
class QueryResult;
QueryResult query(const string& s)const;
};
class TextQuery::QueryResult
{
friend std::ostream& print(std::ostream&, const QueryResult&);
public:
QueryResult(const std::string& s): a(s){}
static string member;
string a;
};
// this is very important to define this method after class QueryResult //get its body
TextQuery::QueryResult
TextQuery::query(const string& s)const
{
return TextQuery::QueryResult(s);
}
std::ostream&
print(std::ostream& os, const TextQuery::QueryResult& s)
{
return os << s.a;
}
string TextQuery::QueryResult::member = "SoS";
int main(int argn, char** args)
{
TextQuery q;
auto a = q.query("xiaozhang");
print(cout,a);
return 0;
}
c++ 嵌套类
最新推荐文章于 2023-05-25 10:33:56 发布