Problem w/ porting and static...

This is a discussion on Problem w/ porting and static... within the C++ Programming forums, part of the General Programming Boards category; I've run into a problem trying to port a program of mine from C to C++, I am using MSVC++. ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    752

    Problem w/ porting and static...

    I've run into a problem trying to port a program of mine from C to C++, I am using MSVC++.

    Code:
    Controller.obj : error LNK2001: unresolved external symbol "private: static struct Color (*  PixelBuffer::myPixelBuffer)[512]" (?myPixelBuffer@PixelBuffer@@0PAY0CAA@UColor@@A)
    Code:
    #ifndef PixelBuffer_h
    #define PixelBuffer_h
    
    #include "Types.h"
    
    class PixelBuffer {
    private:
    	PixelBuffer () {}; // Can't create one.
    	static Color myPixelBuffer[512][512]; // <-- Error here
    
    public:
    	static void put (int x, int y, Color color) {PixelBuffer::myPixelBuffer[x][y] = color;}
    	static void display (
    		void (*initialize) (int width, int depth),
    		void (*process) (int x, int y, Color color),
    		void (*finalize) (void))
    	{
    		
    		int i, j;
    		initialize (512, 512);
    		for (i = 0; i < 512; i++) {
    			for (j = 0; j < 512; j++) {
    				process (i, j, myPixelBuffer[i][j]);
    			}
    		}
    
    		finalize();
    
    		return;
    	}
    }; // End class PixelBuffer
    
    #endif
    Code:
    /*
    typedef struct {
    	int red;
    	int green;
    	int blue;
    } Color;
    */
    
    struct Color {
    	int red, green, blue;
    };
    Now, I'm a little stuck. I don't suppose anyone knows the remedy to this problem?
    Callou collei we'll code the way
    Of prime numbers and pings!

  2. #2
    Ted
    Ted is offline
    Registered User
    Join Date
    Aug 2001
    Posts
    52
    Could it be that your typedef struct Color has been commented out?

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    It doesn't matter whether I use the typedef, or the C++ style struct.

    Also, maybe I should have mentioned this, that last code block is a snippet from Types.h
    Callou collei we'll code the way
    Of prime numbers and pings!

  4. #4
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    If you're using

    static Color myPixelBuffer[512][512];

    you'll probably have to define it (something like) -

    Color PixelBuffer::myPixelBuffer[512][512];

    outside the class

    What you've got is just the declaration when it's a static member (because you don't need to create an instance of the class for the variable to exist). If this doesn't help post more of the code and the reason you've made the constructor private.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Thanks Sorensen. Creating a PixelBuffer.cpp with this made it work:
    Code:
    #include "Types.h"
    #include "PixelBuffer.hpp"
    
    Color PixelBuffer::myPixelBuffer[512][512];
    Callou collei we'll code the way
    Of prime numbers and pings!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. vsnprintf portability problem
    By ichijoji in forum C Programming
    Replies: 2
    Last Post: 06-10-2006, 02:37 PM
  2. static char in function problem
    By cpeschke in forum C Programming
    Replies: 3
    Last Post: 02-15-2005, 07:44 PM

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