Permission Denied -using latest c++ compiler

This is a discussion on Permission Denied -using latest c++ compiler within the C++ Programming forums, part of the General Programming Boards category; My program is binary serach tree... how can i modify it so i can avoid file permission problems.. using ubuntu ...

  1. #1
    Registered User thriller500's Avatar
    Join Date
    Oct 2011
    Posts
    25

    Unhappy Permission Denied -using latest c++ compiler

    My program is binary serach tree...
    how can i modify it so i can avoid file permission problems..

    using ubuntu 12.10
    Attached Files Attached Files

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,496
    Inlined
    Code:
    #include<iostream>
    #include<string>
    using namespace std;
    class node
    {
    private:
    	int data;
    	node *left;
    	node *right;
    public:
    	node(int d)
    	{
    		data=d;
    		cout<<data<<endl;
    		left=NULL;
    		right=NULL;
    	}
    	friend class list;
    };
    class list
    {
        public:
        	node *root;
        	void insert(int data)
        	{
        		if(root==NULL)
        		{
        			root=new node(data);
        		}
        		else if(data>root->data)
        		{
        			insert(root->right,data);
        		}
        		else if(data<root->data)
        		{
        			insert(root->left,data);
        		}
        	}
        	void insert(node *nd,int data)
        	{
        			if(nd==NULL)
        		{
        			nd=new node(data);
        		}
        		else if(data>nd->data)
        		{
        			insert(nd->right,data);
        		}
        		else if(data<nd->data)
        		{
        			insert(nd->left,data);
        		}
        	}
    
    };
    int main()
    {
    	list l;
    	l.insert(9);
    	l.insert(6);
    	
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,261
    No need. There is nothing in that source file which does anything that would cause file permission problems.

    If you are encountering such problems, it is specific to your environment, and has nothing to do with C++ programming. You'll therefore need to work out the answer for yourself.
    Right 98% of the time, and don't care about the other 3%.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,496
    > if(root==NULL)
    Do you have a constructor, which initialised root to NULL?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User thriller500's Avatar
    Join Date
    Oct 2011
    Posts
    25

    It worked

    Quote Originally Posted by Salem View Post
    > if(root==NULL)
    Do you have a constructor, which initialised root to NULL?
    You Are Awesome..
    Thanks Sir..
    I thought it was initialised default to null
    by adding

    Code:
    list()
    {
       root=NULL;
    }
    solved the problem

  6. #6
    Registered User thriller500's Avatar
    Join Date
    Oct 2011
    Posts
    25
    @salem
    Thanks for inlining it sir
    Last edited by thriller500; 11-07-2012 at 03:18 AM.

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    2,364
    since you're using ubuntu 12.10, you have gcc 4.6, so you can add compiler option -std=c++0x, and use the nullptr keyword in place of NULL. I highly recommend this.

  8. #8
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,301
    Better yet, learn about constructor initialisation lists:
    Code:
    list() : root(NULL) {}
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. permission denied in windows 7
    By narendrav in forum C Programming
    Replies: 4
    Last Post: 03-16-2011, 12:26 PM
  2. redirecting - 'permission denied'
    By metros in forum C Programming
    Replies: 11
    Last Post: 02-11-2010, 01:54 PM
  3. execl permission denied
    By NLFortier in forum C Programming
    Replies: 3
    Last Post: 11-03-2009, 08:31 PM
  4. Permission Denied
    By Morgul in forum Windows Programming
    Replies: 2
    Last Post: 06-01-2005, 04:31 PM
  5. Permission Denied error
    By ChazWest in forum C Programming
    Replies: 7
    Last Post: 03-08-2002, 04:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21