Like Tree2Likes
  • 2 Post By Mario F.

Arguing with my compiler (constructor failure)

This is a discussion on Arguing with my compiler (constructor failure) within the C# Programming forums, part of the General Programming Boards category; File1: Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Fie; namespace TwoArgConstructor { class Program { Foo myfoo; ...

  1. #1
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Arguing with my compiler (constructor failure)

    File1:
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Fie;
    namespace TwoArgConstructor
    {
        class Program
        {
            Foo myfoo;
            static void Main(string[] args)
            {
            }
            public void Initialize()
            {
                myfoo = new Foo(1, 2);
            }
        }
    }
    File2:
    Code:
    namespace Fie
    {
        class Foo
        {
            Foo(int a, int b) { }
    
        }
    }
    Error: Fie.Foo does not contain a constructor that takes two arguments

    Yes it does! Can anyone see what is wrong here?

    Quzah.
    Last edited by quzah; 09-24-2011 at 06:19 PM.
    Hope is the first step on the road to disappointment.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The answer is that it was a visibility issue. I didn't know constructors had to be plublic. That doesn't really make sense, but that's what it was.

    File2:
    Code:
    namespace Fie
    {
        class Foo
        {
            public Foo(int a, int b) { }
    
        }
    }
    The MSND link to the error: Compiler Error CS1729 - didn't actually explain the issue, but I saw their use of the keyword public which I added and found that it did indeed fix the issue.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,412
    For ideas around the concept of a private constructor, see here.

    Meanwhile, if you have a chance grab a hold of Pro C# 2010 and the .Net Platform. I noticed the other day when you said that you hadn't reached the ref keyword yet. Argument passing is really at the core of the language, and should come very early. So I suspected that whatever you were basing your studies one wasn't probably the best for you. That book, on the other hand, has everything you will ever want to know about C# and taught in the proper order. It's possibly the most complete book on the language.
    quzah and Elkvis like this.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I have had that sitting in my cart, I just haven't gotten around to buying it. I've been half-heartedly fiddling around with C# here and there, but I really should just go ahead and get what's in my cart. I've been putting it off for no particular reason.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    2,292
    Quote Originally Posted by Mario F. View Post
    For ideas around the concept of a private constructor, see here.

    Meanwhile, if you have a chance grab a hold of Pro C# 2010 and the .Net Platform. I noticed the other day when you said that you hadn't reached the ref keyword yet. Argument passing is really at the core of the language, and should come very early. So I suspected that whatever you were basing your studies one wasn't probably the best for you. That book, on the other hand, has everything you will ever want to know about C# and taught in the proper order. It's possibly the most complete book on the language.
    I have the 2008 version of that book, in hardcover form, and I agree. it is the most complete reference I've seen, short of the MSDN library, and in most cases, it has much better examples than MSDN.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What does a call to `some` constructor mean to the compiler ?
    By manasij7479 in forum C++ Programming
    Replies: 8
    Last Post: 06-22-2011, 11:20 AM
  2. Replies: 6
    Last Post: 05-19-2010, 04:03 AM
  3. Constructor failure
    By Brian in forum C++ Programming
    Replies: 5
    Last Post: 02-24-2005, 01:57 PM
  4. compiler error on class constructor
    By skorman00 in forum C++ Programming
    Replies: 4
    Last Post: 11-04-2003, 11:02 PM

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