Thread: Attempting to make a threadsafe construct

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Don't worry so much about the thread-safety. I know what I'm doing there, and things will be thread-safe. I'm a semi-competent programmer who went on a bit of a hiatus so things are a bit rusty.

    So it turns out my example wasn't exactly as I remembered it (just took a look at the code again) and what I'm trying isn't compiling. So let's try this again...

    Code:
    #include <iostream>
    
    class A;
    
    class B {
    public:
    	 void setA1(int A1);
    	 void copy(void);
    	 void print(void);
    private:
    	 A a1, a2;
    };
    
    class A {
    public:
            friend void B::copy(void);
    	friend void B::setA1(int A1);
    	friend void B::print(void);
    
    private:
            int _a;
    };
    
    
    void B::setA1(int A1)
    {
         a1._a = A1;
    }
    
    void B::copy(void)
    {
         a2._a = a1._a;
    }
    
    void B::print(void)
    {
         std::cout<<a1._a<<" "<<a2._a<<std::endl;
    }
    
    int main(void){
    
    	B b;
    	b.setA1(5);
    	b.copy();
    
    	b.print();
    	std::cin.get();
    	return 0;
    }
    Again doesn't compile. What's the general "rule" here to indicate to the compiler a lack of infinite recursion.

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by golfinguy4 View Post
    Code:
    #include <iostream>
    
    class A;
    
    class B {
    public:
    	 void setA1(int A1);
    	 void copy(void);
    	 void print(void);
    private:
    	 A a1, a2; // You cannot have an instance of A here, since it is not defined yet -- forward declaration is not enough
    };
    
    class A {
    public:
            friend void B::copy(void);
    	friend void B::setA1(int A1);
    	friend void B::print(void);
    
    private:
            int _a;
    };
    Code:
    
    
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by golfinguy4 View Post
    Don't worry so much about the thread-safety. I know what I'm doing there, and things will be thread-safe. I'm a semi-competent programmer who went on a bit of a hiatus so things are a bit rusty.
    No offense to you, but that is honestly the worst attitude one can have.
    If people have advice, you should really listen to them before deciding that you don't need them (and even so, you should really consider the implications of they've said).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Makefile Problem: None rule to make target
    By chris24300 in forum Linux Programming
    Replies: 25
    Last Post: 06-17-2009, 09:45 AM
  2. Establishing 'make clean' with GNU make
    By Jesdisciple in forum C Programming
    Replies: 9
    Last Post: 04-11-2009, 09:10 AM
  3. How to make a Packet sniffer/filter?
    By shown in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2009, 09:51 PM
  4. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 04:19 AM
  5. make all rule
    By duffy in forum C Programming
    Replies: 9
    Last Post: 09-11-2003, 01:05 PM