xref: /OpenGrok/opengrok-indexer/src/test/resources/sources/c/sample.cxx (revision 2bcacabbe843448903326d34ff21a265b5f37596)
1 // compile me with g++
2 /* this is sample comment } */
3 #include <string>
4 #include <vector>
5 #include <iostream>
6 
7 #define TEST(x) (x)
8 
9 class SomeClass {
10 public:
SomeClass()11     SomeClass() /* I'm constructor */
12         : attr_(0)
13     {
14         std::cout << "Hello" << std::endl;
15     }
16 
~SomeClass()17     ~SomeClass() // destructor
18     {
19         std::cout << "Bye" << std::endl;
20     }
21 
MemberFunc(int a,int b) const22     int MemberFunc(int a, int b) const {
23         // some member function
24         return a + b;
25     }
26 
operator ++(int)27     int operator++(int) {
28         return attr_++;
29     }
30 
31     template<typename T>
TemplateMember(std::vector<T> & v)32     size_t TemplateMember(std::vector<T>& v) {
33         return v.size();
34     }
35 
36 private:
37     int attr_;
38 };
39 
40 namespace ns1 {
41 
42     class NamespacedClass {
43     public:
SomeFunc(const std::string & arg)44         static void SomeFunc(const std::string& arg) {
45             std::cout << arg;
46         }
47     };
48 
49     namespace ns2 {
50 
foo(int a,int b)51         int foo(int a, int b) {
52             SomeClass t;
53             return t.MemberFunc(TEST(a), TEST(b));
54         }
55 
56     }
57 }
58 
bar(int x)59 int bar(int x /* } */)
60 {
61     // another function
62     int d;
63     int f;
64     std::cout << TEST("test { message|$#@$!!#") << std::endl;
65     d = foo(2, 4);
66     f = foo(x, d);
67 
68     /* return
69         some
70          rubish
71     */
72     return d+f;
73 }
74 
75 // main function
main(int argc,char * argv[])76 int main(int argc, char *argv[]) {
77     SomeClass c;
78     int res;
79     std::cout << "this is just a {sample}}" << std::endl;
80 
81     res = bar(20);
82     std::cout << "result = {" << res << "}" << std::endl;
83 
84     std::cout << c.MemberFunc(1, 2) << std::endl;
85     std::cout << c++ << std::endl;
86 
87     return 0; }
88 
89