I created a simple program to test smart pointers. I started with standard library but later I want to use boost. I have such compiling problem:
In file included from main.cpp:1:0:
test.hpp:14:21: error: āpā is not a type
shared_ptr<int>a (p);
^
My files and makefile:
test.hpp:
#include <string>
#include <stdlib.h>
#include <vector>
#include <memory>
#include <boost/filesystem.hpp>
using namespace std;
class test{
private:
int* p = new int(10);
shared_ptr<int>a (p);
public:
test() {}
void get_pointer();
};
test.cpp:
#include "test.hpp"
void test::get_pointer()
{
printf("%s\n",*a.get());
}
main.cpp:
#include "test.hpp"
#include <memory>
using namespace std;
int main()
{
test tescik;
tescik.get_pointer();
int b;
scanf("%d",&b);
return 0;
}
makefile:
tester: main.cpp test.cpp
g++ -o tester -std=c++11 main.cpp test.cpp -lboost_system -lboost_filesystem -lglfw3 -lGLU -lGL -lX11 -lXxf86vm -lXcursor -lrt -lm -lXinerama -lXrandr -lpthread -lXi -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_video -lopencv_objdetect
I know I overextended compilation settings (opengl and boost), but I'll use them later. Any ideas why so simple program doesn't work?
You can't initialize data members like that in older versions of C++. Try this instead: