如何在C ++中返回函数结构的向量

时间:2019-07-14 06:29:26

标签: function c++11 prototype

我正在尝试从我的班级返回一个结构向量,但遇到一些错误。到目前为止,这是我设置的内容:

class trial{

   public:
    struct coords{
      double x,y,z;
    };
    vector<coords> trial::function(vector <double> x1, vector <double> x2);
};

std:vector<coords> function(vector <double> x1, vector <double> x2){

    some math.....
    vector <coords> test;
    return test;
}

错误发生在st :: vector ....说未定义坐标。有什么想法吗?

2 个答案:

答案 0 :(得分:1)

您的意思是,在类之外?应该是(假设您是using std::vector;

vector<trial::coords> trial::function(vector <double> x1, vector <double> x2){

在早期的课堂声明中,不需要资格证明trial::

答案 1 :(得分:0)

可以避免在返回类型中完全命名DECLARE @totalRecords INT Declare @I INT /** CREATE TABLE2 **/ /** Store data here recursed from Table2 **/ CREATE TABLE [dbo].[Table2]( [SNO] [INT] IDENTITY(1,1) PRIMARY KEY, [source_class] [numeric](6, 0) NOT NULL, [source_index] [int] NOT NULL, [source_id] [bigint] NOT NULL, [linkType] [numeric](6, 0) NOT NULL, [destination_class] [numeric](6, 0) NOT NULL, [destination_index] [int] NOT NULL, [destination_id] [bigint] NOT NULL, ) /** prevent duplicate entries caused by parent becoming a child **/ ALTER TABLE Collections ADD CONSTRAINT CollLoop_Stop UNIQUE(destination_class,destination_index) /** Get the first data under the root and put in Table2 **/ INSERT INTO Table2(source_class,source_index,source_id,linkType,destination_class,destination_index,destination_id) SELECT * FROM [PAODS072109].[dbo].[Link_table] lt where linkType=1 and source_index=118066 AND destination_class=1 /** Step through Table2 and Find the children row found and add to Table2. This should end with a list of all prodigy from the Parent **/ SELECT @I=1 SELECT @totalRecords=COUNT([source_class]) FROM [MainDB].[dbo].[Table2] tlt While (@I<=@totalRecords) BEGIN INSERT INTO Table2(source_class,source_index,source_id,linkType,destination_class,destination_index,destination_id) SELECT * FROM [MainDB].[dbo].[Table1] lt where lt.linkType=1 and lt.source_index=(SELECT destination_index FROM Table2 WHERE SNO=@I) AND lt.destination_class=1 SELECT @I=@I+1 SELECT @totalRecords=COUNT([source_class]) FROM [MainDB].[dbo].[Collections] tlt END GO 的一个技巧是尾随返回值:

SNO source_class    source_index    source_id   linkType    destination_class   destination_index   destination_id
1   1   118066  1180660001  1   1   55809   558090001
2   1   118066  1180660001  1   1   55805   558050001
3   1   118066  1180660001  1   1   55804   558040001
4   1   118066  1180660001  1   1   118072  1180720001
5   1   55809   558090001   1   1   89276   892760001
6   1   55809   558090001   1   1   58398   583980001
7   1   55809   558090001   1   1   114355  1143550001
8   1   55809   558090001   1   1   117237  1172370001
9   1   55809   558090001   1   1   114070  1140700001
10  1   55809   558090001   1   1   100281  1002810001
11  1   55809   558090001   1   1   12  120001
12  1   55809   558090001   1   1   91159   911590001
13  1   55809   558090001   1   1   125515  1255150001
14  1   55809   558090001   1   1   89275   892750001
15  1   55809   558090001   1   1   126274  1262740001
16  1   55809   558090001   1   1   91148   911480001
17  1   55809   558090001   1   1   119464  1194640001
18  1   55809   558090001   1   1   127194  1271940001
19  1   55809   558090001   1   1   125605  1256050001
20  1   55809   558090001   1   1   123536  1235360001
21  1   55809   558090001   1   1   128085  1280850001
22  1   55805   558050001   1   1   54923   549230001
23  1   55805   558050001   1   1   116235  1162350001
24  1   55805   558050001   1   1   101549  1015490001
25  1   55805   558050001   1   1   77978   779780001
26  1   55805   558050001   1   1   17465   174650001
27  1   55804   558040001   1   1   75583   755830001
28  1   55804   558040001   1   1   118073  1180730001
29  1   118072  1180720001  1   1   122843  1228430001
30  1   118072  1180720001  1   1   128257  1282570001
31  1   118072  1180720001  1   1   121757  1217570001
32  1   118072  1180720001  1   1   123977  1239770001
33  1   118072  1180720001  1   1   129893  1298930001
34  1   118072  1180720001  1   1   121851  1218510001
35  1   118072  1180720001  1   1   86553   865530001
36  1   118072  1180720001  1   1   57095   570950001
37  1   118072  1180720001  1   1   86255   862550001
38  1   118072  1180720001  1   1   109383  1093830001
39  1   118072  1180720001  1   1   115944  1159440001
40  1   118072  1180720001  1   1   118074  1180740001
41  1   114355  1143550001  1   1   120634  1206340001
42  1   114355  1143550001  1   1   114356  1143560001
43  1   114355  1143550001  1   1   114357  1143570001
44  1   100281  1002810001  1   1   128575  1285750001
45  1   12  120001  1   1   64248   642480001
46  1   12  120001  1   1   9424    94240001
47  1   12  120001  1   1   9927    99270001
48  1   12  120001  1   1   11575   115750001
49  1   12  120001  1   1   113729  1137290001
50  1   12  120001  1   1   11528   115280001
51  1   12  120001  1   1   8238    82380001
52  1   12  120001  1   1   76854   768540001
53  1   12  120001  1   1   75634   756340001
54  1   12  120001  1   1   66769   667690001
55  1   12  120001  1   1   60427   604270001
56  1   12  120001  1   1   112271  1122710001
57  1   12  120001  1   1   99284   992840001