Thread: ambiguous symbol

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    40

    ambiguous symbol

    Hey everyone, I was just wondering if anyone could explain why this code won't compile. The compiler says that max is an ambiguous symbol. I just don't see where the ambiguity is.

    Code:
    app.cpp(8) : error C2872: 'max' : ambiguous symbol
    
    could be 'app.cpp(4) : const int max'      or       'max'
    and here's the code

    Code:
    const int max=100;
    
    class queue
    {
    	char q[max];
    	int putter,getter;
    	int size;
    
    public:
    
    	queue(int a)
    	{
    		if (a>max) a=max;
    		if (a<=0) a=1;
    
    		size=a;
    		putter=getter=0;
    	}
    };
    thanks for the help

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    most likely its because the compiler either has a function or macro called max. Which compiler are you using?

    Also by convention user defined global consts or user defined macros should be all caps

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    max is a standard library symbol. The other definition is getting pulled in from a #include.

    Just rename you're max to something else for now.

    gg

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Or don't have a global std namespace import. And make you sure you #define NOMINMAX before #including windows.h.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Jun 2004
    Posts
    40
    im using vc++2003. thanks guys, i can easily rename it to something else

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  4. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM
  5. <list>
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 02-24-2002, 04:07 PM