c++ - A string inside of a struct inside of a class -
i can't seem following code compile. if replace string references char * compile , run fine. using visual studio 2013. missing? have spent several hours trying figure out.
these of compile errors: error 1 error c2146: syntax error : missing ';' before identifier 'ss' c:\users\visual studio 2013\projects\class struct test\class struct test\class struct test.cpp 16 1 class struct test
error 2 error c4430: missing type specifier - int assumed. note: c++ not support default-int c:\users\visual studio 2013\projects\class struct test\class struct test\class struct test.cpp 16 1 class struct test
thanks in advance.
#include "stdafx.h" #include <iostream> #include <string> class test { public: struct structtype { int int1; int int2; string ss; }; public: int getint1(); int getint2(); string getstring(); test() { privatevar.int1 = 5; privatevar.int2 = 6; privatevar.ss = "this test string 1"; }; ~test(){}; private: structtype privatevar; }; using namespace std; int _tmain(int argc, _tchar* argv[]) { test t; cout << "int 1: " << t.getint1() << endl; cout << "int 2: " << t.getint2() << endl; cout << "string: " << t.getstring() << endl; }; int test::getint1() { return privatevar.int1;} int test::getint2() { return privatevar.int2;} string test::getstring(){ return privatevar.ss; }
you meant use standard library string. located in std namespace. try this:
struct structtype { int int1; int int2; std::string ss; };
Comments
Post a Comment